Ahsan Aasim
Ahsan Aasim

Reputation: 1297

Amazon SES mail not getting sent using nodemailer

Trying to use amazon ses for my website to send emails through my website. My app is developed using nodejs and sending mails using nodemail & nodemailer-ses-transport. But getting the following error.

{ AccessDenied: User `arn:aws:iam::755682848022:user/shajao.email' is not authorized to perform `ses:SendRawEmail' on resource `arn:aws:ses:us-east-1:755682848022:identity/shajao.com'
    at Request.extractError (/Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/protocol/query.js:47:29)
    at Request.callListeners (/Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at Request.emit (/Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/request.js:685:12)
    at Request.callListeners (/Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
    at Request.emit (/Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/request.js:685:12)
    at Request.callListeners (/Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
    at callNextListener (/Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/sequential_executor.js:95:12)
    at IncomingMessage.onEnd (/Volumes/Zotac 120GB/6sense/printit/printit-backend/node_modules/aws-sdk/lib/event_listeners.js:269:13)
    at emitNone (events.js:110:20)
    at IncomingMessage.emit (events.js:207:7)
    at endReadableNT (_stream_readable.js:1059:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)
  message: 'User `arn:aws:iam::755682848022:user/shajao.email\' is not authorized to perform `ses:SendRawEmail\' on resource `arn:aws:ses:us-east-1:755682848022:identity/shajao.com\'',
  code: 'AccessDenied',
  time: 2017-12-25T10:49:05.129Z,
  requestId: '39942938-e961-11e7-aa22-07070e500047',
  statusCode: 403,
  retryable: false,
  retryDelay: 32.881228690068795 }

My code is as follows:

var transporter = nodemailer.createTransport(sesTransport({
        accessKeyId: SESCREDENTIALS.accessKeyId,
        secretAccessKey: SESCREDENTIALS.secretAccessKey,
        rateLimit: 5
    }));


    var mailOptions = {
        "from": "Shajao Customer Service<[email protected]>",
        "to": to,
        "subject": subject,
        "text": text,
        "html": html
    };

    transporter.sendMail(mailOptions, cb);

created user in IAM in aws console and added my access key id and secret id. But still isnt working. not sure how to add `ses:SendRawEmail\'

Upvotes: 3

Views: 2964

Answers (1)

alwe
alwe

Reputation: 1497

You need to put a policy or role for your user in IAM:

{
    "Version": "2012-10-17",
    "Statement": [
    {
       "Effect": "Allow",
       "Action": ["ses:SendEmail", "ses:SendRawEmail"],
       "Resource":"*"
     }
    ]
 }

IAM -> Users -> your user (shajao.email?) -> add inline policy

Upvotes: 3

Related Questions