4

我正在尝试使用 Amazon SES 发送电子邮件。

我可以使用我们的本地 SMTP 服务器发送电子邮件,也可以使用亚马逊网站上提供的示例发送电子邮件。

我需要通过电子邮件发送“发件人地址”和“收件人地址”名称。我无法使用 Amazon SDK 中提供的 SendEmailRequest 类来执行此操作,因为WithSource(toaddress), WithDestination(destinationaddress)&WithReplyToAddresses(replytoaddress)方法没有这样的重载,因此我无法在此处从发件人 7 接收者传递名称,因此我使用的是使用 Amazon 配置发送邮件的常规方法.

我尝试了通过代码硬编码以及通过文件进行配置来传递凭据的两种方式,但是在使用端口 587 时,在此错误之上的两种方式仍然出现相同的错误,

“SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:需要身份验证”

尝试使用 465 端口时收到此错误,“发送电子邮件失败”

当尝试使用 IP 地址而不是亚马逊服务器的主机地址时出现此错误。

“根据验证程序,远程证书无效。”

请建议我在这里缺少什么,

这是我的代码,

 MailMessage mail = new MailMessage();
 mail.From = new System.Net.Mail.MailAddress(FromEmail, FromName);

 SmtpClient smtp = new SmtpClient("email-smtp.us-east-1.amazonaws.com", 587);                

 smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
 smtp.UseDefaultCredentials = false;
 smtp.EnableSsl = true;
 smtp.Credentials = new NetworkCredential(AWSAccessKey, AWSSecretKey); 

 //recipient address
 mail.To.Add(new MailAddress(ToEmail, ToName));

 //Formatted mail body
 mail.IsBodyHtml = true;
 mail.Body = strBody;
 smtp.Send(mail);

提前致谢..!!!

4

1 回答 1

0

我通过使用以下格式的电子邮件用户名传递电子邮件解决了这个问题

用户名<example@domain.com>

来自亚马逊网站的样本已经为我工作,

这是我的工作代码,

 AWSCredentials objAWSCredentials = new BasicAWSCredentials(AWSAccessKey, AWSSecretKey);

 Destination destination = new Destination().WithToAddresses(new List<string>() { TO });

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

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

 // Assemble the email.
 SendEmailRequest request = new SendEmailRequest().WithSource(FROM).WithDestination(destination).WithMessage(message).WithReplyToAddresses(REPLYTO);

 // Instantiate an Amazon SES client, which will make the service call. Since we are instantiating an 
 // AmazonSimpleEmailServiceClient object with no parameters, the constructor looks in App.config for 
 // your AWS credentials by default. When you created your new AWS project in Visual Studio, the AWS
 // credentials you entered were added to App.config.
 AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(objAWSCredentials);

 // Send the email.
 Console.WriteLine("Attempting to send an email through Amazon SES by using the AWS SDK for .NET...");
 client.SendEmail(request);

这里我以这种格式传递了 FROM、TO 和 ReplyToAddress,用户名<example@domain.com>

于 2013-08-06T12:25:04.577 回答