简体   繁体   English

无法使用 System.Net.Mail.SmtpClient 将 email 发送到其他域

[英]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:运行此代码时,会发生以下两种情况之一:

  • If RECIPIENT_ADDRESS is the equal to MY_OWN_ADDRESS, or another email address on my domain, the email sends and all is well.如果 RECIPIENT_ADDRESS 等于 MY_OWN_ADDRESS,或者我域上的另一个 email 地址,则 email 发送并且一切正常。
  • However, if RECIPIENT_ADDRESS is any email address, working or otherwise, on another server such as gmail, an exception occurs during SmtpClient.Send:但是,如果 RECIPIENT_ADDRESS 是任何 email 地址,在另一台服务器(例如 gmail)上工作或以其他方式工作,则在 SmtpClient.Send 期间发生异常:

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.

相关问题 如何在Xamarin中使用System.Net.Mail.SmtpClient发送邮件 - How to send a mail in Xamarin using System.Net.Mail.SmtpClient 使用System.Net.Mail.SmtpClient发送的电子邮件的字体大小 - Font size for an email sent using System.Net.Mail.SmtpClient 使用System.Net.Mail.SmtpClient将电子邮件发送到通讯组列表 - Sending email to a distribution list using System.Net.Mail.SmtpClient 发送到 System.Net.Mail.SmtpClient 等文件夹 - Send to folder like System.Net.Mail.SmtpClient 使用System.Net.Mail.SmtpClient,更改SMTP FROM电子邮件地址 - Using System.Net.Mail.SmtpClient, change the SMTP FROM email address System.Net.Mail.SmtpClient 在 4.7 中过时了吗? - Is System.Net.Mail.SmtpClient obsolete in 4.7? 第三方与System.Net.Mail.SmtpClient - Third-party vs System.Net.Mail.SmtpClient 如何使用TLS和System.Net.Mail.SMTPCLient连接到googlemail.com? - How can I connect to googlemail.com using TLS and System.Net.Mail.SMTPCLient? System.Net.Mail.SmtpClient 在发送电子邮件时使用什么类型的身份验证? - What type of authentication is System.Net.Mail.SmtpClient using when sending emails? 使用TLS和SmtpAuth在.Net 4 / C#中发送带有System.Net.Mail.SmtpClient的电子邮件,可在本地使用,但不能在生产服务器上运行(win 2008 r2) - Sending email with System.Net.Mail.SmtpClient in .Net 4/C# with TLS and SmtpAuth, works locally but not on production server(win 2008 r2)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM