关于jmail邮件发送的问题
protected void Button1_Click(object sender, EventArgs e)
{
//我这里测试的邮件账号是codeany@163.com
//测试的密码是就不投入给大家了,改成自己的密码就好了
//接受邮箱可以随便写一个你自己喜欢的邮箱
jmail.Message Jmail = new jmail.Message(); //创建一个jmail对象
String Subject = "邮件测试"; //设置发送邮件的主题
String body = "来自测试邮件"; //设置发送邮件的内容
String FromEmail = "593981469@qq.com"; //发送的邮箱
String ToEmail = "425445289@qq.com"; //接受的邮箱
Jmail.Silent = true; //安静的发送邮件
Jmail.Charset = "GB2312"; //设置发送邮件的字符集
Jmail.ContentType = "text/html";
Jmail.AddRecipient(ToEmail); //添加发送的邮件
Jmail.From = FromEmail; //从何处发送
Jmail.MailServerUserName = "123"; //发件人姓名
Jmail.MailServerPassWord = "*********"; //发件邮件的密码
Jmail.Subject = Subject; //发件邮件的主题
Jmail.AddAttachment(@"d:\data.txt", true, null); //添加I目下面的data.txt文件
Jmail.Body = body; //添加发送邮件的内容
//Jmail.DeferredDelivery = new DateTime(2012, 9, 11,18,0,0); //设置发送邮件的延迟时间 //这个163不行
try
{
Jmail.Send("smtp.qq.com", false);
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
//发送邮件的服务器
Response.Write("<script language='javascript'>alert('密码已成功发送到指定邮箱,请查收!');</script>");
Jmail.Close();
}
[解决办法]
MailMessage objMailMessage = new MailMessage();
objMailMessage.From = new MailAddress("@qq.com");//发送方地址
objMailMessage.To.Add(mailAddress);
// objMailMessage.To.Add(new MailAddress(mailAddress));//收信人地址
objMailMessage.BodyEncoding = System.Text.Encoding.UTF8;//邮件编码
objMailMessage.Subject = mailTitle;//邮件标题
objMailMessage.Body = mailContent;//邮件内容
objMailMessage.IsBodyHtml = true;//邮件正文是否为html格式
SmtpClient objSmtpClient = new SmtpClient();
objSmtpClient.Host = "smtp.qq.com";// mailHost;//邮件服务器地址
objSmtpClient.Credentials = new System.Net.NetworkCredential("@qq.com", "");//发送方的邮件地址,密码
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//通过网络发送到stmp邮件服务器
objSmtpClient.EnableSsl = true;//SMTP 服务器要求安全连接需要设置此属性
objSmtpClient.Send(objMailMessage);