将asp.net core 2.0中的邮件发送到Amazon SES

时间:2017-11-16 02:25:28

标签: c# amazon-web-services .net-core amazon-ses

我做了一个简单的表格,当它提交时,我希望它在亚马逊发送邮件到我的SES提供商。 我怎样才能实现这一点,.NET Core 2.0中是否有允许发送邮件的库?

顺便说一句:我在前端使用了角度,而后端则使用了WebAPI。

1 个答案:

答案 0 :(得分:2)

是的,您可以非常轻松地实现这一点,因为AWSSDK完全支持.net Core 2.0。

安装AWSSDK.SimpleEmail

然后:

    public async Task<bool> SendEmail(string from, string to, string subject, string html){
    // might want to provide credentials
    using(var ses = new AmazonSimpleEmailServiceClient(RegionEndpoint.USEast1)) 

       {
    var sendResult = await ses.SendEmailAsync(new SendEmailRequest
            {
                  Source = from,
                  Destination = new Destination(to) { CcAddresses = "if you need them", BccAddresses = "or these" },
                  Message = new Message
                     {
                       Subject = new Content(subject),
                       Body = new Body
                       {
                          Html = new Content(html)
                       }
                     }
                 });
         return sendResult.HttpStatusCode == HttpStatusCode.OK;
       }
}