AWS SES with Meteor
Asked Answered
C

2

2

I'm trying to out a Meteor package to interface with AWS SES called tarang:email-ses built by @Akshat.

I'm on Meteor @1.* running on a AWS EC2 instance. When I a test run with the code below, no email was sent out.

Meteor Code

I've set up the AWS access key ID and secret access key and use it here:

Meteor.startup(function () {    
  Email.configSES({
    AWSAccessKeyID: 'access-key',
    AWSSecretKey: 'secret-key'
  });
});

I've also verified my emails and domain. Here I make sure I'm sending from my verified sender SES address:

Accounts.emailTemplates.from = 'Domain Name <[email protected]>';

Then in a Meteor method, I create a new user and send and enrollment email like so (this works if I deploy to meteor.com, without the Accounts.emailTemplates.from of course):

if (Meteor.user() && adminUser(this.userId)) {
  var accountId = Accounts.createUser({
    'username': doc.name,
    'email': doc.email
  });
  Accounts.sendEnrollmentEmail(accountId);
}

Questions

Is the code to set things up for the email-ses package correct?

I thought this package abstracted out the Amazon SES API to Send Email (and allowed for native Meteor email calls). Is there a requirement to set up SMTP on AWS?

Cavender answered 21/1, 2015 at 2:32 Comment(0)
C
8

To send email in Meteor the easiest thing to do is to set the SMTP server and username information using process.env.MAIL_URL variable. The Accounts and Email packages will automatically use it to access the SMTP server whenever you send a message.

To enable SMTP access with AWS SES:

  1. Log into the AWS Management Console
  2. Select the appropriate region where you set up SES.
  3. Select SES from the list of Application Services
  4. Click the SMTP Settings menu item in the left menu
  5. Click the Create My SMTP Credentials button
  6. Use the default IAM username that's provided. This is a special IAM user that will only have access to the SMTP server. You shouldn't use your main IAM username/password when accessing the SMTP server.
  7. Make sure to note the SMTP server name. You'll need it later.
  8. After the account is created download the credentials.

Now that you have an account set up, simply copy and paste the following line to the top of your Meteor startup file and replace the username and password from the values in the credential file that you just downloaded and the server name that was provided.

process.env.MAIL_URL = 'smtp://username:password@smtp-server-name:465';

Please note that both the sending and receiving email addresses must be verified in the AWS SES management console if you haven't received production access yet. If you don't do this Meteor will throw an error in the console and the message will not be sent.

Cascio answered 21/1, 2015 at 16:27 Comment(9)
This solution this works great -- it's clean and simple. The only drawback is I have to send to a verified email address of course (only if I use there SMTP). This is a pain as, should my clients going to get Amazon verification emails before I send them the account sign up emails? If that's my only option, is there an API call to automate that too?Cavender
Once you're ready you can request production access to SES. After you're approved you can send emails to any address without it being verified. You only need to verify the sending email address or domain in production mode. The process to get production access is rather complicated though. You need handle bounce and complaint notifications from SES and prevent messages from being sent to those addresses in the future. If you don't handle these notifications AWS may shut you down. docs.aws.amazon.com/ses/latest/DeveloperGuide/…Cascio
Thanks. I put in a request for production access. Should I open another question on here on handling these scenarios in meteor?Cavender
I would. There are a lot of steps involved in getting everything set up, depending on how you choose to implement it. It's better to isolate each issue to a separate question, to make it easier for other SO users to find a solution later.Cascio
I added a question to SO related to setting up SES Production Access with Meteor: #28080670 Thanks!Cavender
In order to get this working I needed to encode both the username and password with encodeURIComponent.Barefaced
Just wanted to mention you need to set the email used in Meteor like this: docs.meteor.com/api/passwords.html#Accounts-emailTemplatesInverness
@TimFletcher Your comment made my day. Thank you. With SES you indeed need to encoreURIComponent() at least the password. in the MAIL_URL. Also, if you use the port 465, you need to update the mail url with smtps instead of smtp. Thank you mateAmalburga
Please note it is encodeURIComponent not encoreURIComponent.Detrusion
A
2

@brian-shamblen does not answer the question directly, but rather proposes an alternative solution to send emails.

You do not have to set up SMTP on AWS, nor you need to set environment variable inside your project process.env.MAIL_URL.

  • Log into the AWS Management Console
  • Go to IAM Service (!!not SES)
  • Create new IAM User
  • Save credentials (AWSAccessKeyID and AWSSecretKey). These are the credentials you'll use in Email.configSES({...})
  • Create inline Policy for this user:
{   
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ses:SendEmail",
                "ses:SendRawEmail"
            ],
            "Resource": "*"
        }
    ]
}
  • Make sure to use verified domail in Accounts.emailTemplates.from. In order to verify domain in AWS, go to SES services -> Domains and follow instructions.

This should let you send emails.

Antediluvian answered 18/2, 2016 at 18:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.