SMTP服务器需要安全连接或客户端未经过身份验证 - 错误

时间:2013-08-06 11:36:29

标签: c# .net amazon-ses

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

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

我需要发送发送地址&使用电子邮件寻址姓名。我无法使用Amazon SDK中提供的SendEmailRequest类执行此操作,因为WithSource(toaddress)WithDestination(destinationaddress)& WithReplyToAddresses(replytoaddress)方法,所以我不能在这里传递名称发送者7接收者,所以我使用常规方法使用亚马逊配置发送邮件。

我尝试通过硬编码通过代码以及通过按文件进行配置来传递凭据,但是当使用端口587时,我仍然遇到与此错误相同的错误,

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

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

尝试使用IP地址代替amazon服务器的主机地址时出现此错误。

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

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

这是我的代码,

 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);

先谢谢.. !!!

1 个答案:

答案 0 :(得分: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&amp;这种格式的ReplyToAddress, 用户名&lt; example@domain.com&gt;