.net中Smtp发送邮件需要认证的解决办法
blog中原来有文章介绍过发送需要身份验证邮件的解决办法:
http://www.cnblogs.com/theone/archive/2004/05/10/8809.aspx。采用这个方法需要在项目中引用CDO,还有一种解决办法是:
MailMessage testMail = new MailMessage();
testMail.From = "test@test.com";
testMail.To = "test@test.com";
testMail.Subject = "Test remote";
testMail.BodyFormat = MailFormat.Html;
testMail.Body = "Test Mail";
testMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
testMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "username"); //set your username here
testMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password"); //set your password here
MailAttachment mailAttach = new MailAttachment(@"E:\Test.Rar");
testMail.Attachments.Add(mailAttach);
SmtpMail.SmtpServer.Insert(0,"61.55.142.1");
SmtpMail.Send(testMail);
虽然认证那三行代码看起来有点莫名其妙,可是还是比较好用的。