You are on the right track, but ultimately you would need to use the HTTP.call()
method on the server-side in order to create a POST/GET
request to Amazon's SES service.
First be sure to have the following packages installed for Meteor
through Meteorite
-
mrt add crypto-base
mrt add crypto-base64
mrt add crypto-hmac
mrt add crypto-md5
mrt add crypto-sha1
mrt add crypto-sha256
Also make sure you have the http
Meteor package meteor add http
.
Secondly get your AWS AccessKeyId
,secretAccessKey
combo - only the keyID
is shown on Amazon, if you don't remember the secretKey
you would just have to regenerate both of them.
var url = 'https://email.us-east-1.amazonaws.com',
awsAKID = '<Access Key ID goes here>',
secretAccessKey = '<Secret Access Key goes here>',
signature = '',
currentDate = new Date().toUTCString(),
xAmznHeader = '',
emailContent = '',
resultSend = '-1';
// Encrypt the currentDate with your secretAccessKey
// afterwards encode it in base64
// Note: that you can substitute the SHA256 with SHA1 for lower encryption
signature = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(currentDate, secretAccessKey));
// this is the POST request header that Amazon uses to verify the validity of your request
xAmznHeader = 'AWS3-HTTPS AWSAccessKeyId=' + awsAKID + ', Algorithm=HmacSHA256, Signature=' + signature;
emailContent =
'From: <your verified sender e-mail here>\n' +
'To: <wherever you want to send it>\n' +
'Date: ' + currentDate +'\n' +
'Subject: Hi There\n' +
'MIME-Version: 1.0\n' +
'Content-Type: multipart/mixed; boundary="someBoundaryNameHere"\n' +
'--someBoundaryNameHere\n' +
'Content-Transfer-Encoding: 7bit\n\n' +
// body starts here, SES wants you to seperate the header from the body
//with an empty line, notice the extra '\n' above
'Readable text here\n' +
'--someBoundaryNameHere\n' +
'Content-Type: application/xml;\n' +
xmlString +
'\r\n';
// now we base64 encode the whole message, that's how Amazon wants it
emailContent = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(emailContent));
// we can finally make the POST request
resultSend = HTTP.call("POST", url, {
params: {
Action : "SendRawEmail",
"RawMessage.Data" : emailContent
},
headers : {
'Date' : currentDate,
'X-Amzn-Authorization' : xAmznHeader
}
});