0
有沒有人有使用最新的Amazon AWS SDK 2.3.6通過SES SMTP發送電子郵件的經驗?我目前有一個API密鑰,祕密和smtp_url。AWS iOS SDK:通過AWSSES發送電子郵件
謝謝!
有沒有人有使用最新的Amazon AWS SDK 2.3.6通過SES SMTP發送電子郵件的經驗?我目前有一個API密鑰,祕密和smtp_url。AWS iOS SDK:通過AWSSES發送電子郵件
謝謝!
只是想通了。我承認亞馬遜的文檔有點密集。希望這可以幫助別人!
AWSSESSendEmailRequest *awsSESSendEmailRequest = [AWSSESSendEmailRequest new];
awsSESSendEmailRequest.source = @"[email protected]";
AWSSESDestination *awsSESDestination = [AWSSESDestination new];
awsSESDestination.toAddresses = [NSMutableArray arrayWithObjects:@"[email protected]",nil];
awsSESSendEmailRequest.destination = awsSESDestination;
AWSSESMessage *awsSESMessage = [AWSSESMessage new];
AWSSESContent *awsSESSubject = [AWSSESContent new];
awsSESSubject.data = @"Subject goes here";
awsSESSubject.charset = @"UTF-8";
awsSESMessage.subject = awsSESSubject;
AWSSESContent *awsSESContent = [AWSSESContent new];
awsSESContent.data = @"Message goes here";
awsSESContent.charset = @"UTF-8";
AWSSESBody *awsSESBody = [AWSSESBody new];
awsSESBody.text = awsSESContent;
awsSESMessage.body = awsSESBody;
awsSESSendEmailRequest.message = awsSESMessage;
AWSStaticCredentialsProvider *credentialsProvider = [[AWSStaticCredentialsProvider alloc] initWithAccessKey:@"ACCESS-KEY"
secretKey:@"SECRET-KEY"];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSWest2
credentialsProvider:credentialsProvider];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
[[AWSSES defaultSES] sendEmail:awsSESSendEmailRequest completionHandler:^(AWSSESSendEmailResponse * _Nullable response, NSError * _Nullable error) {
if (error)
{
// error
}
else
{
// success
}
}];
在下面的Swift 3.0中發送電子郵件的代碼片段。
let serviceRegionType = AWSRegionType.usEast1
let credentialsProvider = AWSStaticCredentialsProvider.init(accessKey: "access", secretKey: "secret")
let configuration = AWSServiceConfiguration(region: serviceRegionType, credentialsProvider: credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
let subject = AWSSESContent()
subject?.data = "Subject"
subject?.charset = "UTF-8"
let messageBody = AWSSESContent()
messageBody?.data = "Sample Message body"
messageBody?.charset = "UTF-8"
let body = AWSSESBody()
body?.text = messageBody
let theMessage = AWSSESMessage()
theMessage?.subject = subject
theMessage?.body = body
let destination = AWSSESDestination()
destination?.toAddresses = ["toaddress"]
let send = AWSSESSendEmailRequest()
send?.source = "source mail"
send?.destination = destination
send?.message = theMessage
AWSSES.default().sendEmail(send!) { (response:AWSSESSendEmailResponse?, mailError: Error?) in
print(mailError?.localizedDescription)
if ((response?.messageId) != nil) {
print("Mail has delivered succesfully")
} else {
print("Mail has failed to delivered")
}
}
感謝上面的代碼。我有另一個需要通過AWS SES發送文件的需求。我知道必須同樣使用sendRawEmail API。任何人可以幫助示例代碼片段? – Ganesh