奇怪的问题,.Net 2.0发送邮件失败...
生活随笔
收集整理的這篇文章主要介紹了
奇怪的问题,.Net 2.0发送邮件失败...
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
.Net 1.1中發送郵件使用System.Web.Mail.而到.Net 2.0中發送郵件建議使用System.Net.Mail,不推薦使用System.Web.Mail,但是原來的還能用,今天將原來1.1發送程序改寫成2.0,但是一直是發送失敗,一直被諾頓攔截,很奇怪,而且把諾頓Internet Email Auto Protected關閉就能發送出去.原來1.1從來沒有諾頓攔截現象.
根據上面的鏈接查詢Symantec Support KB,解釋如下:
1? Start Outlook Express.?
2? Click the Tools menu, and then click Accounts.?
3? In the Internet Accounts list, click the name of the account that you use to send email.?
4? Click Properties.
5? Click the Advanced tab.
6? Under Server Timeouts, drag the slider so that the number of minutes increases. The maximum time that you can set it to is 5 minutes.
7? Click OK.?
8? Click Close.
暈死,設置發送超時時間為 5 Min
但是將發送TimeOut設為5*60*1000仍然發送失敗,搞不懂了
?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????????????//?Set?the?content
10????????????oMsg.Subject?=?"My?First?.NET?email";
11????????????oMsg.Body?=?"Test?body?-?.NET?Rocks!";
12????????????oMsg.IsBodyHtml?=?true;
13????????????System.Net.Mail.SmtpClient?oSmtp?=?new?System.Net.Mail.SmtpClient("smtp.126.com");
14????????????//You?can?choose?several?delivery?methods.?
15????????????//Here?we?will?use?direct?network?delivery.
16????????????oSmtp.DeliveryMethod?=?System.Net.Mail.SmtpDeliveryMethod.Network;
17????????????oSmtp.Timeout?=?5?*?60?*?1000;
18????????????//Some?SMTP?server?will?require?that?you?first?
19????????????//authenticate?against?the?server.
20????????????NetworkCredential?oCredential?=?new?NetworkCredential("upzone",?"123456");
21????????????oSmtp.UseDefaultCredentials?=?false;
22????????????oSmtp.Credentials?=?oCredential;
23????????????//Let's?send?it?already
24????????????oSmtp.Send(oMsg);
25
26????????}
發送不成功,沒有辦法,只好改回原來1.1的發送程序,等解決了2.0的問題再說了.
?1????????public?void?SendSmtpMail()
?2????????{
?3????????????System.Web.Mail.MailMessage?mail?=?new?System.Web.Mail.MailMessage();
?4????????????mail.To?=?"upzone@126.com";
?5????????????mail.From?=?"upzone@126.com";
?6????????????mail.Subject?=?"this?is?a?test?email.";
?7????????????mail.Body?=?"Some?text?goes?here";
?8????????????mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",?"1");?//basic?authentication?
?9????????????mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",?"upzone");?//set?your?username?here?
10????????????mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",?"123456");?//set?your?password?here?
11
12????????????System.Web.Mail.SmtpMail.SmtpServer?=?"smtp.126.com";?//your?real?server?goes?here?
13????????????System.Web.Mail.SmtpMail.Send(mail);?
14
15????????}
根據上面的鏈接查詢Symantec Support KB,解釋如下:
1? Start Outlook Express.?
2? Click the Tools menu, and then click Accounts.?
3? In the Internet Accounts list, click the name of the account that you use to send email.?
4? Click Properties.
5? Click the Advanced tab.
6? Under Server Timeouts, drag the slider so that the number of minutes increases. The maximum time that you can set it to is 5 minutes.
7? Click OK.?
8? Click Close.
暈死,設置發送超時時間為 5 Min
但是將發送TimeOut設為5*60*1000仍然發送失敗,搞不懂了
?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????????????//?Set?the?content
10????????????oMsg.Subject?=?"My?First?.NET?email";
11????????????oMsg.Body?=?"Test?body?-?.NET?Rocks!";
12????????????oMsg.IsBodyHtml?=?true;
13????????????System.Net.Mail.SmtpClient?oSmtp?=?new?System.Net.Mail.SmtpClient("smtp.126.com");
14????????????//You?can?choose?several?delivery?methods.?
15????????????//Here?we?will?use?direct?network?delivery.
16????????????oSmtp.DeliveryMethod?=?System.Net.Mail.SmtpDeliveryMethod.Network;
17????????????oSmtp.Timeout?=?5?*?60?*?1000;
18????????????//Some?SMTP?server?will?require?that?you?first?
19????????????//authenticate?against?the?server.
20????????????NetworkCredential?oCredential?=?new?NetworkCredential("upzone",?"123456");
21????????????oSmtp.UseDefaultCredentials?=?false;
22????????????oSmtp.Credentials?=?oCredential;
23????????????//Let's?send?it?already
24????????????oSmtp.Send(oMsg);
25
26????????}
發送不成功,沒有辦法,只好改回原來1.1的發送程序,等解決了2.0的問題再說了.
?1????????public?void?SendSmtpMail()
?2????????{
?3????????????System.Web.Mail.MailMessage?mail?=?new?System.Web.Mail.MailMessage();
?4????????????mail.To?=?"upzone@126.com";
?5????????????mail.From?=?"upzone@126.com";
?6????????????mail.Subject?=?"this?is?a?test?email.";
?7????????????mail.Body?=?"Some?text?goes?here";
?8????????????mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",?"1");?//basic?authentication?
?9????????????mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",?"upzone");?//set?your?username?here?
10????????????mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",?"123456");?//set?your?password?here?
11
12????????????System.Web.Mail.SmtpMail.SmtpServer?=?"smtp.126.com";?//your?real?server?goes?here?
13????????????System.Web.Mail.SmtpMail.Send(mail);?
14
15????????}
轉載于:https://www.cnblogs.com/upzone/archive/2006/04/25/384343.html
總結
以上是生活随笔為你收集整理的奇怪的问题,.Net 2.0发送邮件失败...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qomo OpenProject bet
- 下一篇: 有时候,爱就是那么简单