奇怪的问题,.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从来没有诺顿拦截现象.
![](/images/cnblogs_com/upzone/nortoninterruptmail.jpg)
根据上面的链接查询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仍然发送失败,搞不懂了
发送不成功,没有办法,只好改回原来1.1的发送程序,等解决了2.0的问题再说了.
![](/images/cnblogs_com/upzone/nortoninterruptmail.jpg)
根据上面的链接查询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仍然发送失败,搞不懂了
1
public 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![](/Images/OutliningIndicators/InBlock.gif)
26
}
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](/Images/OutliningIndicators/InBlock.gif)
4
![](/Images/OutliningIndicators/InBlock.gif)
5
![](/Images/OutliningIndicators/InBlock.gif)
6
![](/Images/OutliningIndicators/InBlock.gif)
7
![](/Images/OutliningIndicators/InBlock.gif)
8
![](/Images/OutliningIndicators/InBlock.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/InBlock.gif)
12
![](/Images/OutliningIndicators/InBlock.gif)
13
![](/Images/OutliningIndicators/InBlock.gif)
14
![](/Images/OutliningIndicators/InBlock.gif)
15
![](/Images/OutliningIndicators/InBlock.gif)
16
![](/Images/OutliningIndicators/InBlock.gif)
17
![](/Images/OutliningIndicators/InBlock.gif)
18
![](/Images/OutliningIndicators/InBlock.gif)
19
![](/Images/OutliningIndicators/InBlock.gif)
20
![](/Images/OutliningIndicators/InBlock.gif)
21
![](/Images/OutliningIndicators/InBlock.gif)
22
![](/Images/OutliningIndicators/InBlock.gif)
23
![](/Images/OutliningIndicators/InBlock.gif)
24
![](/Images/OutliningIndicators/InBlock.gif)
25
![](/Images/OutliningIndicators/InBlock.gif)
26
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
发送不成功,没有办法,只好改回原来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![](/Images/OutliningIndicators/InBlock.gif)
12
System.Web.Mail.SmtpMail.SmtpServer = "smtp.126.com"; //your real server goes here
13
System.Web.Mail.SmtpMail.Send(mail);
14![](/Images/OutliningIndicators/InBlock.gif)
15
}
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](/Images/OutliningIndicators/InBlock.gif)
4
![](/Images/OutliningIndicators/InBlock.gif)
5
![](/Images/OutliningIndicators/InBlock.gif)
6
![](/Images/OutliningIndicators/InBlock.gif)
7
![](/Images/OutliningIndicators/InBlock.gif)
8
![](/Images/OutliningIndicators/InBlock.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/InBlock.gif)
12
![](/Images/OutliningIndicators/InBlock.gif)
13
![](/Images/OutliningIndicators/InBlock.gif)
14
![](/Images/OutliningIndicators/InBlock.gif)
15
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)