提示是:The message was undeliverable. All servers failed to receive the message 第2页
试试这个,绝对好用,我就这么用的
public static void SendEmail(string from, string to, string cc, string subject, string body, string attachment)
{
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(from, to, subject, body);
mail.CC.Add(new MailAddress(cc));
mail.Attachments.Add(new Attachment(attachment));
mail.IsBodyHtml = false;
System.Net.Mail.SmtpClient send = new System.Net.Mail.SmtpClient("smtp.gmail.com");
send.Port = 587;// gmail;
send.EnableSsl = true;
send.UseDefaultCredentials = false;
send.Credentials = new NetworkCredential("username", "password");
send.Send(mail);
}
public static bool sendEmail(string EmailAddress, string RecipientName,string PGPKey,string strHtml,string MailTitle)
{
bool isNo = false;
jmail.Message jmessage = new jmail.MessageClass();
jmessage.Charset = "GB2312";
jmessage.From = "55276937@qq.com";//发送邮件人的邮箱
jmessage.FromName = "第一英才";//发送邮件人的用户名
jmessage.ReplyTo = "55276937@qq.com";//跟上边一样的
jmessage.ContentType = "text/html";
jmessage.Charset = "GB2312";
jmessage.ContentTransferEncoding = "base64";
jmessage.Encoding = "base64";
jmessage.Subject = MailTitle;//标题
jmessage.AddRecipient(EmailAddress, RecipientName, PGPKey);//收件人
jmessage.Body = strHtml;//内容
jmessage.MailServerUserName = "55276937@qq.com";//发件人用户名
jmessage.MailServerPassWord = "123456a";//发件人用户密码
if(jmessage.Send("smtp.qq.com", false))// smtp
{
isNo = true;
}else
{
isNo = true;
}
//Response.Write("email sent successfully!");
jmessage.Close();//注意这里,一定要关闭连接 否则邮件发不出去
return isNo;
}