0

I don't have much web dev experience but I'm trying to add to my club's web app on p5.js editor. 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?

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.

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.

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107

1 Answers1

0

Questions like this are best answered by reading through the API and documentation for the library you're using, in this case Mandrill.

Googling "Mandrill JavaScript API" returns a ton of results, including this one:

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

This page is the documentation for the Mandrill library. 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.

Also see this related question: How to send an email with Mandrill using JavaScript?

Note that using Mandrill in browser-side JavaScript is a very bad idea! 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. 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.

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107