[英]upload .jpg image attachment in mail using AWS SES from node.js
[英]Sending mail via aws ses with attachment in node.js
有沒有人有一些示例說明如何使用 aws ses 在node.js
發送帶有附件的電子郵件?
如果你想避免痛苦,你必須使用包裹在 Nodemailer 中的 SES。 直接使用 AWS 開發工具包,你不能用ses.sendEmail
發送附件,你必須使用ses.sendRawEmail
,這很糟糕,因為你必須用標題和其他東西來形成原始電子郵件,甚至在我做了之后那個,我有一個奇怪的錯誤,發送了重復的電子郵件......
npm install nodemailer
const AWS = require('aws-sdk');
const nodemailer = require("nodemailer");
async function scheduledEmail () {
let usefulData = 'some,stuff,to,send';
let transporter = nodemailer.createTransport({
SES: new AWS.SES({ region: 'us-east-1', apiVersion: "2010-12-01" })
});
let text = 'Attached is a CSV of some stuff.';
// send mail with defined transport object
let info = await transporter.sendMail({
from: '"Some name" <someone@example.com>',
to: "someone_else@example.com",
subject: "Hello", // Subject line
text: text, // plaintext version
html: '<div>' + text + '</div>', // html version
attachments: [{
filename: "usefulData.csv",
content: usefulData
}]
});
console.log("Message sent: %s", info.messageId);
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
return info; // or something
}
有很多其他設置附件方式的例子: https : //nodemailer.com/message/attachments/
如果您仍處於 SES 沙盒模式,則必須驗證兩個收件人/發件人地址。 在 SES 發送統計信息頁面申請退出沙箱模式。
有一個很棒的郵件庫,稱為 ˇNodemailerˇ,它也支持 Amazon SES。 這是一個如何發送帶有附件的電子郵件的小例子https://github.com/nodemailer/nodemailer/blob/master/examples/ses.js
但請注意,當您的電子郵件發送失敗時,亞馬遜會出現奇怪的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.