建议你用CDO发送是微软的, m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", mailname); //set your username here m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", mailpwd); //set your password here SmtpMail.SmtpServer = smtp;
然后在asp.net 的web.config里配置下就可以了欢迎访问我的视频搜索引擎:http://www.vzhangmen.com
还有个问题就是,我用HTML的FILEFILD控件添加邮件附件,提示没有访问权限,我给了ASPNET权限后可以了,如果我把程序放虚拟空间上,访问我网站的人需要这样设置吗?126的邮箱好像不需要设置就可以添加附件的!
System.Net.Mail.SmtpClient client = new SmtpClient("smtp.163.com");
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("user", "pwd");
client.DeliveryMethod = SmtpDeliveryMethod.Network; System.Net.Mail.MailMessage message = new MailMessage("发件人", "收件人", "标题", "内容");
//message.BodyEncoding = System.Text.Encoding.UTF8;
message.BodyEncoding = Encoding.GetEncoding("GB2312");
message.SubjectEncoding = Encoding.GetEncoding("GB2312");
message.IsBodyHtml = true;
client.Send(message);
string server, int port,
string user, string pass,
System.Net.Mail.MailMessage mail
)
{
System.Net.Mail.SmtpClient client = new SmtpClient(server, port);
client.DeliveryMethod = SmtpDeliveryMethod.Network;//指定发送方式 Network是直接用smtp发送
client.Credentials = new System.Net.NetworkCredential(user, pass);
client.Send(mail);
return true;
}
具体代码就不写了。一搜索就有了
m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", mailname); //set your username here
m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", mailpwd); //set your password here
SmtpMail.SmtpServer = smtp;