如何使用 System.Net.Mail.SmtpClient 从 AT&T 住宅帐户发送电子邮件?
抱歉,如果这应该是超级用户的问题,但这似乎是我遇到的 .NET 配置问题,而不是我的 ISP 的问题。
我正在尝试使用 System.Net.Mail.SmtpClient 发送电子邮件。我使用的是 AT&T Uverse 住宅线路,因此出站端口 25 被完全阻止,发送电子邮件的唯一方法是通过他们批准的 SMTP 服务器,通过端口 465,通过 SSL。这些设置可以在这里找到:https://www.att。 com/esupport/article.jsp?sid=KB401570&ct=9000812。当我尝试使用我认为 SmtpClient 的正确设置发送电子邮件时,我得到的只是“System.IO.IOException:无法从传输连接读取数据:现有连接被远程主机强制关闭。 ”
这是我的代码:
var client = new SmtpClient();
client.Host = "smtp.att.yahoo.com";
client.Port = 465;
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("[email protected]", "password");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
var message = new MailMessage();
message.From = new MailAddress("[email protected]");
message.To.Add(new MailAddress("[email protected]"));
message.Subject = "Subject";
message.Body = "This is the body";
client.Send(message);
调用 client.Send(message) 时发生异常。我还尝试使用 App.config,如下所示:
<configuration>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network
host="smtp.att.yahoo.com"
port="465"
defaultCredentials="false"
enableSsl="true"
userName="[email protected]"
password="password"
/>
</smtp>
</mailSettings>
</system.net>
</configuration>
并留下 C# 代码:
var client = new SmtpClient();
var message = new MailMessage();
message.From = new MailAddress("[email protected]");
message.To.Add(new MailAddress("[email protected]"));
message.Subject = "Subject";
message.Body = "This is the body";
client.Send(message);
是否还有其他我应该使用的设置?有人成功通过 smtp.att.yahoo.com
从 .NET 发送电子邮件吗?我可以说这在 Outlook 中确实有效,所以它不像某个地方有什么障碍。
编辑: Gmail 已退出,因为我需要能够保持发件人地址动态,而 Gmail 会强制发件人使用该帐户。即我有一个域,我需要能够从@mydomain.com 发送。
Apologies if this should be on SuperUser, but this appears to be a .NET configuration issue I'm having rather than an issue with my ISP.
I'm trying to send out e-mail using System.Net.Mail.SmtpClient. I'm on an AT&T Uverse residential line, so outbound port 25 is completely blocked and the only way to send e-mail is through their approved SMTP server, over port 465, over SSL. The settings can be found here: https://www.att.com/esupport/article.jsp?sid=KB401570&ct=9000812. When I try to send e-mail using what I assume are the correct settings for SmtpClient, all I get is "System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."
Here's my code:
var client = new SmtpClient();
client.Host = "smtp.att.yahoo.com";
client.Port = 465;
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("[email protected]", "password");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
var message = new MailMessage();
message.From = new MailAddress("[email protected]");
message.To.Add(new MailAddress("[email protected]"));
message.Subject = "Subject";
message.Body = "This is the body";
client.Send(message);
The exception occurs on the call to client.Send(message). I've also tried using App.config as follows:
<configuration>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network
host="smtp.att.yahoo.com"
port="465"
defaultCredentials="false"
enableSsl="true"
userName="[email protected]"
password="password"
/>
</smtp>
</mailSettings>
</system.net>
</configuration>
and just left by C# code as:
var client = new SmtpClient();
var message = new MailMessage();
message.From = new MailAddress("[email protected]");
message.To.Add(new MailAddress("[email protected]"));
message.Subject = "Subject";
message.Body = "This is the body";
client.Send(message);
Are there other settings I should be using? Has anyone had success in sending e-mail from .NET through smtp.att.yahoo.com
? I can say that this does work in Outlook, so it's not like there's some block somewhere.
EDIT: Gmail is out because I need to be able to keep the from address dynamic and gmail forces the sender to the account. i.e. I have a domain and I need to be able to send from @mydomain.com.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已成功使用非安全端口 587 通过 smtp.att.yahoo.com 发送电子邮件:
I've managed to send emails through smtp.att.yahoo.com using the non secure port 587: