TNND....费了我一个晚上的时间(上次在公司是费了我半天的时间都发不了)才成功发送....
ASP.NET 2.0发送Smtp电子邮件真是麻烦.....搜索了好多资料(163,QQ,Sina,126)...都不成功....最后找到一个还算正常的..但就是发送不出....然后又找到另一个....两个结合起来就成功了....- -|| ....
using System; using System.Net.Mail; using System.Net; using System.Text; public class Utilities
{
public static void SendSMTPEMail()
{
MailMessage message = new MailMessage("发送人邮箱", "收件人邮箱");
message.Subject = "邮件标题";
message.Body = "邮件内容";
message.SubjectEncoding = Encoding.GetEncoding( "gb2312");
message.BodyEncoding = Encoding.GetEncoding( "gb2312");
message.IsBodyHtml = true;
message.Priority = MailPriority.Normal;
SmtpClient clint = new SmtpClient( "smtp.gmail.com 邮箱服务器");
clint.UseDefaultCredentials = false;
clint.EnableSsl = true;
clint.Credentials = new System.Net.NetworkCredential( "[email protected] 邮箱", "邮箱密码");
clint.DeliveryMethod = SmtpDeliveryMethod.Network;
clint.Send(message);
message.Dispose();
}
public static void Main()
{
SendSMTPEMail();
}
}
gmail的邮件发送成功率高,所以推荐使用smtp.gmail.com ,反正现在gmail申请已经不需要邀请了,还是蛮方便的吧
|
请发表评论