我正在尝试使用 Amazon SES 发送电子邮件。运行此程序时我没有收到任何错误,但什么也没有发生。我试图找到文档,但亚马逊在这方面做得很糟糕。那么,有什么想法吗?编辑:我也在 Amazon SES 控制台中验证了我尝试发送的邮件。
这是我目前所得到的:
let sns = AWSSES.defaultSES()
var messageBody = AWSSESContent()
var subject = AWSSESContent()
var body = AWSSESBody()
subject.data = "Subject"
messageBody.data = "Message body"
body.text = messageBody
var message = AWSSESMessage()
message.subject = subject
message.body = body
var destination = AWSSESDestination()
destination.toAddresses = ["emailadress@gmail.com"]
var send = AWSSESSendEmailRequest()
send.source = "emailadress@gmail.com"
send.destination = destination
send.message = message
sns.sendEmail(send).continueWithSuccessBlock {(task: BFTask!) -> BFTask! in
NSLog("Sent mail - success")
return nil
}
}
最佳答案
所以,问题是我没有为 SES 服务使用正确的区域。工作代码:
let credentialProvider = AWSCognitoCredentialsProvider.credentialsWithRegionType(
CognitoRegionType,
identityPoolId: CognitoIdentityPoolId)
let configuration = AWSServiceConfiguration(
region: SESServiceRegionType,
credentialsProvider: credentialProvider)
var sns = AWSSES(configuration: configuration)
var messageBody = AWSSESContent()
var subject = AWSSESContent()
var body = AWSSESBody()
subject.data = "Subject"
messageBody.data = "Message body"
body.text = messageBody
var theMessage = AWSSESMessage()
theMessage.subject = subject
theMessage.body = body
var destination = AWSSESDestination()
destination.toAddresses = ["emailadress@gmail.com"]
var send = AWSSESSendEmailRequest()
send.source = "emailadress@gmail.com"
send.destination = destination
send.message = theMessage
send.returnPath = "emailadress@gmail.com"
sns.sendEmail(send).continueWithBlock {(task: AnyObject!) -> BFTask! in
return nil
}
关于swift - 如何在 Swift 中使用 Amazon SES 发送电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31162163/