string fromAddress = "***@gmail.com"; System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add(targetAddress);
msg.From = new System.Net.Mail.MailAddress(fromAddress,"***");
msg.BodyEncoding = System.Text.Encoding.UTF8;
/* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/
msg.Subject = title;//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = content;//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = true;//是否是HTML邮件
msg.Priority = System.Net.Mail.MailPriority.High;//邮件优先级
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Credentials = new System.Net.NetworkCredential(fromAddress, "***");
//上述写你的GMail邮箱和密码
client.Port = 587;//Gmail使用的端口
client.Host = "smtp.gmail.com";
client.EnableSsl = true;//经过ssl加密
object userState = msg;
client.SendAsync(msg, userState);
以上是我发邮件的代码在本地是可以成功的,测了N次,发到服务器上时,就发送不了,无任何异常信息,求大侠指教下哈,急
msg.To.Add(targetAddress);
msg.From = new System.Net.Mail.MailAddress(fromAddress,"***");
msg.BodyEncoding = System.Text.Encoding.UTF8;
/* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/
msg.Subject = title;//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = content;//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = true;//是否是HTML邮件
msg.Priority = System.Net.Mail.MailPriority.High;//邮件优先级
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Credentials = new System.Net.NetworkCredential(fromAddress, "***");
//上述写你的GMail邮箱和密码
client.Port = 587;//Gmail使用的端口
client.Host = "smtp.gmail.com";
client.EnableSsl = true;//经过ssl加密
object userState = msg;
client.SendAsync(msg, userState);
以上是我发邮件的代码在本地是可以成功的,测了N次,发到服务器上时,就发送不了,无任何异常信息,求大侠指教下哈,急
防火墙要怎么设置 ,能给出相关文章吗?
Smtp无法夸防火墙,而且Smtp协议是根据网站邮箱版本来定
2000年以前基本都是Smtp协议