如何使用AWS-SDK的简单电子邮件服务从角度应用程序发送带有附件的电子邮件

时间:2019-03-29 09:10:58

标签: angular aws-sdk amazon-ses

我正在尝试使用aws-ses从我的角度应用程序发送带有附件(blob)的电子邮件。我没有收到附件,但收到了电子邮件。 (blob包含JSON。)

这是我的代码:

sendEmail(blob: any, completedCallback) {
    let rawMessage = '';
    let buffer = JSON.stringify(blob);
    rawMessage += 'To: someone@example.com\n';
    rawMessage += 'From: snnoreply@example.com\n';
    rawMessage += 'Subject: Hello, World!\n';
    rawMessage += '\n';
    rawMessage += 'MIME-Version: 1.0\n';
    rawMessage += 'Content-Type: multipart/mixed; boundary=\"NextPart\"\n\n';
    rawMessage += '--NextPart\n';
    rawMessage += 'Content-Type: text/html; charset=us-ascii\n\n';
    rawMessage += 'This is the body of the email.\n';
    rawMessage += '--NextPart\n';
    rawMessage += 'Content-Type: application/json;\n';
    rawMessage += 'Content-Disposition: attachment; filename=\"attachment.txt\"\n\n';
    rawMessage += buffer + '\n\n';
    rawMessage += '--NextPart--';
    let eParams = {
        RawMessage: {
            Data: rawMessage
        },
        Destinations: ['somone@example.com'],
        Source: '<snnoreply@example.com>'
    };
    this.ses.sendRawEmail(eParams, function(err, resp) {
        if (err) {
            console.log('failed with error: ' + err);
            err['msg1'] = 'Email sending failed';
            completedCallback(err);
        } else {
            console.log('===EMAIL SENT===');
            resp['msg1'] = 'Email sent';
            completedCallback(resp);
        }
    });
    console.log('EMAIL CODE END');
}

我的代码中是否有错误/不完整。请指出正确的方向。

0 个答案:

没有答案