[英]Unable to send email to other domains using System.Net.Mail.SmtpClient
Please look at the following code:请看下面的代码:
client.Credentials = new NetworkCredential(SMTP_SERVER_USERNAME, SMTP_SERVER_PASSWORD);
client.EnableSsl = false;
client.Host = SMTP_SERVER_HOSTNAME;
client.Port = 587;
client.UseDefaultCredentials = false;
client.Timeout = 4000;
MailMessage message = new MailMessage();
message.Body = "Test";
message.From = new MailAddress(MY_OWN_ADDRESS);
message.ReplyToList.Add(message.From);
message.Sender = message.From;
message.Subject = SUBJECT_LINE;
message.To.Add(RECIPIENT_ADDRESS);
I am currently unable to use it to send emails.我目前无法使用它来发送电子邮件。 The code resides in an ASP.NET MVC 3 application using the old ASPX engine.
该代码位于使用旧 ASPX 引擎的 ASP.NET MVC 3 应用程序中。 It runs on an IIS7 server with ASP.NET 4.0 in Integrated Pipeline mode.
它在集成管道模式下运行在具有 ASP.NET 4.0 的 IIS7 服务器上。
When this code is run, one of twothings happens:运行此代码时,会发生以下两种情况之一:
Mailbox unavailable.信箱不可用。 The server response was: Authentication is required for relay
服务器响应是:中继需要身份验证
Description : An unhandled exception occurred during the execution of the current web request.说明:在执行当前 web 请求期间发生未处理的异常。 Please review the stack trace for more information about the error and where it originated in the code.
请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
Exception Details : System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable.异常详细信息:System.Net.Mail.SmtpFailedRecipientException:邮箱不可用。 The server response was: Authentication is required for relay
服务器响应是:中继需要身份验证
I noticed your message.To.Add(RECIPIENT_ADDRESS)
might have been a string.我注意到您的
message.To.Add(RECIPIENT_ADDRESS)
可能是一个字符串。 I've had issues with this in the past.我过去遇到过这个问题。 Wrap it in a
MailAddress
object and it should work.将其包装在
MailAddress
object 中,它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.