简体   繁体   English

发送带有附件javascript p5.js的电子邮件

[英]Send email with attachment javascript p5.js

I don't have much web dev experience but I'm trying to add to my club's web app on p5.js editor. 我没有太多的Web开发经验,但是我试图在p5.js编辑器上添加到俱乐部的Web应用程序中。 It's a photobooth application that takes your picture, adds a filter, and emails the picture to you. 这是一个照相亭应用程序,可以拍照,添加滤镜并通过电子邮件将图片发送给您。 I need to do two things for our event in a few days. 我需要在几天内为我们的活动做两件事。

  • I need to send the picture to the user's email. 我需要将图片发送到用户的电子邮件中。
  • I need to store email inputs in an online database. 我需要将电子邮件输入存储在在线数据库中。

Could anyone provide some JavaScript code and/or detailed instructions on how to go about this? 谁能提供一些JavaScript代码和/或详细说明以实现此目标?

This is what I have so far but I honestly don't understand what's happening. 到目前为止,这是我所拥有的,但老实说,我不知道发生了什么。 I haven't figured out the picture attachment yet and I don't know if this format with mandrillapp allows JavaScript image attachments. 我还没有弄清楚图片附件,也不知道mandrillapp的这种格式是否允许JavaScript图像附件。

function sendMail() {
    $.ajax({
      type: 'POST',
      url: 'https://mandrillapp.com/api/1.0/messages/send.json',
      data: {
        'key': '***************',
        'message': {
          'from_email': '*******@gmail.com',
          'to': [
              {
                'email': '************@gmail.com',
                'name': '*******',
                'type': 'to'
              }
            ],
          'autotext': 'true',
          'subject': 'Welcome to AI@UCI!',
          'html': 'Thanks for joining our newsletter! Here is your image :)'
        }
      }
     }).done(function(response) {
       console.log(response);
     });
}

Thank you. 谢谢。

Questions like this are best answered by reading through the API and documentation for the library you're using, in this case Mandrill. 通过阅读所用库(在本例中为Mandrill)的API和文档,可以最好地回答此类问题。

Googling "Mandrill JavaScript API" returns a ton of results, including this one: 谷歌搜索“ Mandrill JavaScript API”会返回大量结果,包括以下结果:

https://mandrillapp.com/api/docs/messages.nodejs.html https://mandrillapp.com/api/docs/messages.nodejs.html

This page is the documentation for the Mandrill library. 此页面是Mandrill库的文档。 It contains code samples that send an image as an attachment. 它包含将图像作为附件发送的代码示例。 Basically it looks like you need to base-64 encode its data and send it that way. 基本上,您似乎需要对数据进行base-64编码并以这种方式发送。

Also see this related question: How to send an email with Mandrill using JavaScript? 另请参阅以下相关问题: 如何使用JavaScript使用Mandrill发送电子邮件?

Note that using Mandrill in browser-side JavaScript is a very bad idea! 请注意,在浏览器端JavaScript中使用Mandrill是一个非常糟糕的主意! To use Mandrill you need to provide your API key, and including your API key in browser-side JavaScript means that anybody who views your page can see your API key. 要使用Mandrill,您需要提供API密钥,并将API密钥包含在浏览器端的JavaScript中,这意味着查看您页面的任何人都可以看到您的API密钥。 This is like giving them your password, and will allow anyone to use your account to send email. 这就像为他们提供密码,并且将允许任何人使用您的帐户发送电子邮件。

Instead, you probably want to set up a server that sends the mail, and make the request from your client-side JavaScript to that server. 相反,您可能想要设置一个发送邮件的服务器,并从客户端JavaScript向该服务器发出请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM