1

我想知道,如果我可以使用System.Net.Mail465 端口和System.Web.Mail587 端口。例如对于 gmail,我不能在这个例子中切换端口,因为它会抛出传输协议异常......

using web = System.Web.Mail;
using net = System.Net.Mail;

private void SendMail()
{
    web.MailMessage webMail = new web.MailMessage();
    webMail.To = "MAILTO@gmail.com";
    webMail.From = "MAILFROM@gmail.com";

    webMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2");
    webMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");            
    webMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
    webMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "LOGIN");
    webMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "PASSWORD");
    webMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);
    web.SmtpMail.SmtpServer = "smtp.gmail.com";
    web.SmtpMail.Send(webMail);

    net.SmtpClient smtp = new net.SmtpClient();
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = new System.Net.NetworkCredential("LOGIN", "PASSWORD");
    smtp.Port = 587;
    smtp.Host = "smtp.gmail.com";
    smtp.EnableSsl = true;

    var netMail = new net.MailMessage(new net.MailAddress("MAILFROM@gmail.com", "", System.Text.Encoding.UTF8),
                                      new net.MailAddress("MAILTO@gmail.com", "", System.Text.Encoding.UTF8));

    smtp.Send(netMail); 
}

我在问,因为即使是最简单的第二个Net.Mail也无法在 .Net 2.0 构建中的俄语 Win 7 64x 下发送 - 它会引发有关标题中无效字符的异常......并且 We.Mail 按预期工作。但是我不想用...

4

0 回答 0