使用 SMTP 通过 C# Winforms 发送 Yahoo 邮件
我使用下面的代码通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能这太简单了,但是雅虎有一个文档使用哪些端口和服务器。
摘录:
Probably this is too easy, but Yahoo has a documentation on which ports and servers to use.
An excerpt:
此位中的所有内容都需要更改以反映 Yahoo 的 SMTP 服务器:
您需要更改这些以反映 此处设置。
关于时间,我怀疑任何信誉良好的开放 SMTP 都会提供任何“快速”服务以防止被用于垃圾邮件。
Everything in this bit would need to change to reflect Yahoo's SMTP server:
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.