如何使用 System.Net.Mail.SmtpClient 从 AT&T 住宅帐户发送电子邮件?

发布于 2024-10-06 23:43:11 字数 2812 浏览 0 评论 0原文

抱歉,如果这应该是超级用户的问题,但这似乎是我遇到的 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安静 2024-10-13 23:43:11

我已成功使用非安全端口 587 通过 smtp.att.yahoo.com 发送电子邮件:

client.Port = 587;
client.EnableSsl = false;

I've managed to send emails through smtp.att.yahoo.com using the non secure port 587:

client.Port = 587;
client.EnableSsl = false;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文