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

时间:2011-11-21 22:24:49

标签: c# winforms email smtp

我正在使用以下代码通过Gmail服务器发送电子邮件。我想知道的是我需要更改/删除下面的代码才能使用我的C#WinForm应用程序从Yahoo邮件服务器发送电子邮件。

而且,如果你知道如何让它的性能更快,请告诉我。使用此代码发送电子邮件需要20到22秒。谢谢。

var fromAddress = new MailAddress("sendermail@gmail.com", "Sender name");
var toAddress = new MailAddress("recipientmail@gmail.com", "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);
}

2 个答案:

答案 0 :(得分:1)

此位中的所有内容都需要更改以反映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;
}

您需要更改这些内容以反映settings here

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

答案 1 :(得分:1)

这可能太容易了,但Yahoo has a documentation on which ports and servers to use

摘录:

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 you@widgetdesigns.com)

Email address:               Your Business Email address
                             (such as you@widgetdesigns.com)

Password:                    Your Business Email password