@阿卜杜拉·阿德卜是正确的。我最终只使用了AWS-SE,并从前端调用它。
/// <reference types="aws-sdk" />
import { Component } from '@angular/core';
import * as aws from 'aws-sdk';
import { SES } from 'aws-sdk'
import { AwsConfig } from '../../../awsConfig';
@Component({
selector: 'app-contact',
templateUrl: './contact.component.html',
styleUrls: ['./contact.component.scss']
})
export class ContactComponent {
private _ses: SES;
constructor() {
this.configureSES();
}
public sendMessage(): void {
let params;
params = {
Destination: {
ToAddresses: [ 'recipient@sample.com' ]
},
Message: {
Body: {
Html: {
Charset: 'UTF-8',
Data: '<h1>HTML needed inside of your email</h1>'
},
Text: {
Charset: 'UTF-8',
Data: 'Or you can use plain text'
}
},
Subject: {
Charset: 'UTF-8',
Data: 'Sample message subject'
}
},
Source: 'sender@sample.com' // Must be registered with AWS
};
this.sendEmail(params);
}
}
private configureSES(): void {
aws.config.credentials = {
accessKeyId: AwsConfig.accessKeyId,
secretAccessKey: AwsConfig.secretAccessKey
};
aws.config.update({
region: AwsConfig.region
});
this._ses = new SES({
apiVersion: '2010-12-01'
});
}
private sendEmail(params): void {
this._ses.sendEmail(params, function(err, data) {
if (err) {
console.log(err, err.stack);
} else {
console.log(data);
}
});
}
}