使用 SMTP 通过 C# Winforms 发送 Yahoo 邮件

发布于 2024-12-17 10:46:33 字数 1150 浏览 0 评论 0原文

我使用下面的代码通过 Gmail 服务器发送电子邮件。我想知道的是,我必须从下面的代码中更改/删除什么才能使用我的 C# WinForm 应用程序从 Yahoo 邮件服务器发送电子邮件。

另外,如果您知道如何提高其性能,请告诉我。使用此代码发送电子邮件大约需要 20 到 22 秒。谢谢。

var fromAddress = new MailAddress("[email protected]", "Sender name");
var toAddress = new MailAddress("[email protected]", "Recipient name");
const string fromPassword = "mypassword";
const string subject = "Subject";
string body = "E-mail content";

var smtp = new SmtpClient();
{
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;
    smtp.EnableSsl = true;
    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.Credentials = new NetworkCredential(fromAddress.Address, fromPassword);
    smtp.Timeout = 20000;
}

using (var message = new MailMessage(fromAddress, toAddress))
{
    message.Subject = subject;
    message.Body = body;
    message.IsBodyHtml = true;

    smtp.Send(message);
}

I'm using the code below to send an e-mail through Gmail server. What I want to know is what do I have to change/remove from the code below to be able to send an e-mail from Yahoo mail server using my C# WinForm application.

And also, if you know how to make it's performance faster, please let me know. It takes like 20 to 22 seconds to send an e-mail using this code. Thank you.

var fromAddress = new MailAddress("[email protected]", "Sender name");
var toAddress = new MailAddress("[email protected]", "Recipient name");
const string fromPassword = "mypassword";
const string subject = "Subject";
string body = "E-mail content";

var smtp = new SmtpClient();
{
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;
    smtp.EnableSsl = true;
    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.Credentials = new NetworkCredential(fromAddress.Address, fromPassword);
    smtp.Timeout = 20000;
}

using (var message = new MailMessage(fromAddress, toAddress))
{
    message.Subject = subject;
    message.Body = body;
    message.IsBodyHtml = true;

    smtp.Send(message);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

空城之時有危險 2024-12-24 10:46:33

可能这太简单了,但是雅虎有一个文档使用哪些端口和服务器

摘录:

Outgoing mail (SMTP) server: smtp.bizmail.yahoo.com
                             Use SSL, port: 465, and use authentication

Account name/user name:      Your Business Email address
                             (such as [email protected])

Email address:               Your Business Email address
                             (such as [email protected])

Password:                    Your Business Email password

Probably this is too easy, but Yahoo has a documentation on which ports and servers to use.

An excerpt:

Outgoing mail (SMTP) server: smtp.bizmail.yahoo.com
                             Use SSL, port: 465, and use authentication

Account name/user name:      Your Business Email address
                             (such as [email protected])

Email address:               Your Business Email address
                             (such as [email protected])

Password:                    Your Business Email password
风铃鹿 2024-12-24 10:46:33

此位中的所有内容都需要更改以反映 Yahoo 的 SMTP 服务器:

var smtp = new SmtpClient();
{
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;
    smtp.EnableSsl = true;
    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.Credentials = new NetworkCredential(fromAddress.Address, fromPassword);
    smtp.Timeout = 20000;
}

您需要更改这些以反映 此处设置

关于时间,我怀疑任何信誉良好的开放 SMTP 都会提供任何“快速”服务以防止被用于垃圾邮件。

Everything in this bit would need to change to reflect Yahoo's SMTP server:

var smtp = new SmtpClient();
{
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;
    smtp.EnableSsl = true;
    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.Credentials = new NetworkCredential(fromAddress.Address, fromPassword);
    smtp.Timeout = 20000;
}

you'll need to change these to reflect the settings here.

With regards to time I doubt any reputable open SMTP will provide any 'fast' service in an attempt to prevent being used for spam.

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