无法使用Amazon SES .NET SDK发送电子邮件。

3

我可以在 .Net 中使用 SMTP 选项发送电子邮件,但是我需要使用 .NET SDK 通过 Amazon 发送电子邮件。它给了我一个错误,说“电子邮件地址未经验证”,尽管我确定已经验证过了。顺便说一下,我正在使用测试帐户(沙盒)。

我做错了什么?还是我漏掉了什么?

以下是我的代码:

var sesClient = new AmazonSimpleEmailServiceClient("AKIAJHXXXXXXXXXXX", "RVGdbCKXILwjUIKSexKlwXXXXXXXXXXXX",Amazon.RegionEndpoint.USEast1);
var dest = new Destination
{
    ToAddresses = new List<string>() { "tayfun.ural@aryxxx.com" },
    CcAddresses = new List<string>() { "arif.yilmaz@aryxxx.com" }
};

var from = "tayfun.ural@aryxxx.com";
var subject = new Content("You're invited to the meeting");
var body = new Body(new Content("Please join us Monday at 7:00 PM."));
var msg = new Message(subject, body);

var request = new SendEmailRequest
{
    Destination = dest,
    Message = msg,
    Source = from
};

var verify = sesClient.VerifyEmailAddress(new VerifyEmailAddressRequest { EmailAddress =     "tayfun.ural@aryada.com" });

try
{
   var response = sesClient.SendEmail(request);
}
catch (Exception ex)
{
    throw ex;
}
2个回答

2
在使用处于沙盒/测试模式的Amazon SES时,所有发件人/收件人/抄送地址必须是已验证的电子邮件地址。出现“电子邮件地址未经验证”的错误意味着至少有一个电子邮件地址未经验证,可能是收件人、发件人、抄送人或密送人之一。在您的情况下,请确保"tayfun.ural@aryxxx.com" 和"arif.yilmaz@aryxxx.com"都已经验证,或者"aryxxx.com"是一个已验证的域名。

1
        String FROM = "SENDER@EXAMPLE.COM";  // Replace with your "From" address. This address must be verified.
        String TO = "RECIPIENT@EXAMPLE.COM"; // Replace with a "To" address. If you have not yet requested
        // production access, this address must be verified.

        String SUBJECT = "Amazon SES test (AWS SDK for .NET)";
        String BODY = "This email was sent through Amazon SES by using the AWS SDK for .NET.";

        // Construct an object to contain the recipient address.
        Destination destination = new Destination();
        destination.ToAddresses = (new List<string>() { TO });

        // Create the subject and body of the message.
        Content subject = new Content(SUBJECT);
        Content textBody = new Content(BODY);
        Body body = new Body(textBody);

        // Create a message with the specified subject and body.
        Message message = new Message(subject, body);

        // Assemble the email.
        SendEmailRequest request = new SendEmailRequest(FROM, destination, message);

        // Choose the AWS region of the Amazon SES endpoint you want to connect to. Note that your production 
        // access status, sending limits, and Amazon SES identity-related settings are specific to a given 
        // AWS region, so be sure to select an AWS region in which you set up Amazon SES. Here, we are using 
        // the US East (N. Virginia) region. Examples of other regions that Amazon SES supports are USWest2 
        // and EUWest1. For a complete list, see http://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html 
        Amazon.RegionEndpoint REGION = Amazon.RegionEndpoint.USEast1;

        // Instantiate an Amazon SES client, which will make the service call.
        AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(REGION);

        // Send the email.
        try
        {
            //("Attempting to send an email through Amazon SES by using the AWS SDK for .NET...");
            client.SendEmail(request);
            //("Email sent!");
        }
        catch (Exception ex)
        {
            //("The email was not sent.");
            //("Error message: " + ex.Message);
        }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接