swift - 如何在 Swift 中使用 Amazon SES 发送电子邮件?

标签 swift amazon-web-services amazon-ses aws-sdk

我正在尝试使用 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/

相关文章:

amazon-web-services - aws sdk lambda列表函数返回空函数数组

php - 在我们使用 AWS SES SMTP 凭证在 PHP 应用程序中发送电子邮件的 AWS SES 中迁移到签名版本 4 的影响?

ios - 当我在 swift 框架中使用 Bridging Headers 时失败

ios - 将颜色渐变添加到圆形进度条 iOS

amazon-web-services - 如何检查消息是否即将超过 MessageRetentionPeriod?

amazon-web-services - 在 AWS Elastic Beanstalk 上安装 bcrypt 失败

amazon-web-services - Amazon SES SMTP 连接超时

python - 向亚马逊 SES 发送电子邮件的最快方式是什么?

ios - 设计表单布局的最佳方法是什么

ios - 快速关闭属性错误访问(EXC_BAD_ACCESS)