奇怪的问题,.Net 2.0发送邮件失败...
生活随笔
收集整理的這篇文章主要介紹了
奇怪的问题,.Net 2.0发送邮件失败...
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
.Net 1.1中發(fā)送郵件使用System.Web.Mail.而到.Net 2.0中發(fā)送郵件建議使用System.Net.Mail,不推薦使用System.Web.Mail,但是原來(lái)的還能用,今天將原來(lái)1.1發(fā)送程序改寫(xiě)成2.0,但是一直是發(fā)送失敗,一直被諾頓攔截,很奇怪,而且把諾頓Internet Email Auto Protected關(guān)閉就能發(fā)送出去.原來(lái)1.1從來(lái)沒(méi)有諾頓攔截現(xiàn)象.
根據(jù)上面的鏈接查詢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.
暈死,設(shè)置發(fā)送超時(shí)時(shí)間為 5 Min
但是將發(fā)送TimeOut設(shè)為5*60*1000仍然發(fā)送失敗,搞不懂了
?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????????}
發(fā)送不成功,沒(méi)有辦法,只好改回原來(lái)1.1的發(fā)送程序,等解決了2.0的問(wèn)題再說(shuō)了.
?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????????}
根據(jù)上面的鏈接查詢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.
暈死,設(shè)置發(fā)送超時(shí)時(shí)間為 5 Min
但是將發(fā)送TimeOut設(shè)為5*60*1000仍然發(fā)送失敗,搞不懂了
?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????????}
發(fā)送不成功,沒(méi)有辦法,只好改回原來(lái)1.1的發(fā)送程序,等解決了2.0的問(wèn)題再說(shuō)了.
?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????????}
轉(zhuǎn)載于:https://www.cnblogs.com/upzone/archive/2006/04/25/384343.html
總結(jié)
以上是生活随笔為你收集整理的奇怪的问题,.Net 2.0发送邮件失败...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Qomo OpenProject bet
- 下一篇: 有时候,爱就是那么简单