Reputation: 61
I am trying to send an email with Amazon SES. I get no errors when I run this, but nothing happens. I've tried to find documentation, but Amazon is quite bad at this. So, any ideas? EDIT: I've verified the mail that I'm trying to send from in the Amazon SES console as well.
This is what I've got so far:
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 = ["[email protected]"]
var send = AWSSESSendEmailRequest()
send.source = "[email protected]"
send.destination = destination
send.message = message
sns.sendEmail(send).continueWithSuccessBlock {(task: BFTask!) -> BFTask! in
NSLog("Sent mail - success")
return nil
}
}
Upvotes: 3
Views: 1194
Reputation: 61
So, the problem was that I wasn't using the right region for the SES service. Working code:
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 = ["[email protected]"]
var send = AWSSESSendEmailRequest()
send.source = "[email protected]"
send.destination = destination
send.message = theMessage
send.returnPath = "[email protected]"
sns.sendEmail(send).continueWithBlock {(task: AnyObject!) -> BFTask! in
return nil
}
Upvotes: 2