无法发送电子邮件使用System.Net.Mail.SmtpClient其他领域 [英] Unable to send email to other domains using System.Net.Mail.SmtpClient

查看:1926
本文介绍了无法发送电子邮件使用System.Net.Mail.SmtpClient其他领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请看看下面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);

我现在无法用它来发送电子邮件。在code驻留在使用旧引擎ASPX一个ASP.NET MVC 3应用程序。它运行在综合管线模式与ASP.NET 4.0 IIS7服务器上。

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. It runs on an IIS7 server with ASP.NET 4.0 in Integrated Pipeline mode.

在运行此code,twothings情况之一:

When this code is run, one of twothings happens:


  • 如果RECIPIENT_ADDRESS是等于MY_OWN_ADDRESS,或在我的域中的另一个电子邮件地址,电子邮件发送,一切都很好。

  • 但是,如果RECIPIENT_ADDRESS任何电子邮件地址,工作或其他方式,另一台服务器(如Gmail)上,SmtpClient.Send期间发生异常:

邮箱无法使用。服务器响应为:验证需要继电器

说明:当前Web请求的执行过程中发生未处理的异常。请查看有关错误的详细信息的堆栈跟踪以及它起源于code。

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

异常详细信息:System.Net.Mail.SmtpFailedRecipientException:邮箱不可用。在服务器响应:身份验证所需的继电器

Exception Details: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: Authentication is required for relay

推荐答案

我注意到你的 message.To.Add(RECIPIENT_ADDRESS)可能是一个字符串。我已经在过去的这个问题。它包装在一个 MailAddress 对象,它应该工作。

I noticed your message.To.Add(RECIPIENT_ADDRESS) might have been a string. I've had issues with this in the past. Wrap it in a MailAddress object and it should work.

这篇关于无法发送电子邮件使用System.Net.Mail.SmtpClient其他领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆