【问题标题】:The SMTP server requires a secure connection or the client was not authenticated - ErrorSMTP 服务器需要安全连接或客户端未通过身份验证 - 错误
【发布时间】:2022-02-25 19:04:35
【问题描述】:

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

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

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

我尝试了通过代码硬编码以及通过文件进行配置来传递凭据的两种方式,但在使用端口 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);

提前致谢..!!!

【问题讨论】:

    标签: c# .net amazon-ses


    【解决方案1】:

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

    用户名

    来自亚马逊网站的示例已经对我有用,

    这是我的工作代码,

     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, 用户名

    【讨论】:

      猜你喜欢
      • 2023-03-21
      • 2011-05-28
      • 2017-12-02
      • 2012-03-06
      • 2015-11-26
      • 2016-09-25
      相关资源
      最近更新 更多