VS2005发送电子邮件(转)
/// <summary>
/// 发送邮件
/// </summary>
/// <param name="sendTo"></param>
/// <param name="subject"></param>
/// <param name="body"></param>
/// <returns></returns>
public static bool SendEmail(string sendTo,string subject,string body)
{
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = "smtp.163.com";
client.UseDefaultCredentials = false;
//client.Credentials = new System.Net.NetworkCredential("发件人邮箱", "******");
client.Credentials = new System.Net.NetworkCredential("你的邮箱", "******");
//星号改成自己邮箱的密码
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("你的邮箱", sendTo);
message.Subject = subject;
message.Body = body;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = false;
//添加附件
//Attachment data = new Attachment(@"附件地址如:e:\a.jpg", System.Net.Mime.MediaTypeNames.Application.Octet);
//message.Attachments.Add(data);
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1685190
/// 发送邮件
/// </summary>
/// <param name="sendTo"></param>
/// <param name="subject"></param>
/// <param name="body"></param>
/// <returns></returns>
public static bool SendEmail(string sendTo,string subject,string body)
{
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = "smtp.163.com";
client.UseDefaultCredentials = false;
//client.Credentials = new System.Net.NetworkCredential("发件人邮箱", "******");
client.Credentials = new System.Net.NetworkCredential("你的邮箱", "******");
//星号改成自己邮箱的密码
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("你的邮箱", sendTo);
message.Subject = subject;
message.Body = body;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = false;
//添加附件
//Attachment data = new Attachment(@"附件地址如:e:\a.jpg", System.Net.Mime.MediaTypeNames.Application.Octet);
//message.Attachments.Add(data);
try
{
client.Send(message);
return true;
//MessageBox.Show("Email successfully send.");
}
catch (Exception ex)
{
return false;
//MessageBox.Show("Send Email Failed." + ex.ToString());
}
}
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1685190
作者: XuGang 网名:钢钢 |
出处: http://xugang.cnblogs.com |
声明: 本文版权归作者和博客园共有。转载时必须保留此段声明,且在文章页面明显位置给出原文连接地址! |