解决了2.0发送邮件问题,原来是发送方式问题

msdn上查到这个SmtpDeliveryMethod,邮件发送方式

SmtpDeliveryMethod

恍然大悟,将SmtpDeliveryMethod指定为PickupDirectoryFromIis,大概是诺顿不允许直连远端smtp吧,先改成由本地IIS里的Smtp来做中转,问题解决了,但是这需要本地安装IIS,SMTP,如果没有安装怎么办?真的要指定SpecifiedPickupDirectory么,我没有试过,有机会再试试看.

 1public void SendNetSmtpMail2()
 2{
 3    System.Net.Mail.MailMessage oMsg = new System.Net.Mail.MailMessage();
 4    // Set the message sender
 5    oMsg.From = new System.Net.Mail.MailAddress("upzone@126.com""upzone");
 6    // The .To property is a generic collection, 
 7    // so we can add as many recipients as we like.
 8    oMsg.To.Add(new System.Net.Mail.MailAddress("upzone@126.com""upzone"));
 9    oMsg.To.Add(new System.Net.Mail.MailAddress("leo@tastysoft.net""leo"));
10    // Set the content
11    oMsg.Subject = "My First .NET email";
12    oMsg.Body = "Test body - .NET Rocks!";
13    oMsg.IsBodyHtml = true;
14    System.Net.Mail.SmtpClient oSmtp = new System.Net.Mail.SmtpClient("smtp.126.com");
15    //You can choose several delivery methods. 
16    //Email is copied to the pickup directory used by a local Internet Information
17        //     Services (IIS) for delivery.    oSmtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.PickupDirectoryFromIis;
18    //oSmtp.PickupDirectoryLocation
19    //oSmtp.Timeout = 5 * 60 * 1000;
20    //Some SMTP server will require that you first 
21    //authenticate against the server.
22    NetworkCredential oCredential = new NetworkCredential("upzone""123456");
23    oSmtp.UseDefaultCredentials = false;
24    oSmtp.Credentials = oCredential;
25    //Let's send it already
26    oSmtp.SendCompleted += new System.Net.Mail.SendCompletedEventHandler(oSmtp_SendCompleted);
27    oSmtp.SendAsync(oMsg,"OK");
28
29}

30
31void oSmtp_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
32{
33    System.Diagnostics.Debug.WriteLine("[smtp]" + e.UserState.ToString());
34    //这里发送成功得到SendAsync里的参数"OK"
35    }
posted @ 2006-04-25 11:30  upzone  阅读(702)  评论(1编辑  收藏  举报