日期:2014-05-17 浏览次数:20698 次
public bool SendEmailToSupplier(string from, string to, string subject, string body) { try { System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(from, to); msg.Subject = subject; msg.Body = body; msg.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312"); msg.Priority = System.Net.Mail.MailPriority.High; System.Net.Mail.SmtpClient cliect = new System.Net.Mail.SmtpClient("smtp.qq.com"); cliect.Credentials = new System.Net.NetworkCredential("692500034@qq.com", "********");//登陆的邮箱名和密码 cliect.Send(msg); return true; } catch (Exception ex) { Response.Write(ex.Message); return false; } }
using System; using System.Net.Mail; using System.Net; /// <summary> /// 说明:在.net2.0以上版本中发送电子邮件的方法示例 /// 用到的类主要位于System.Net.Mail和System.Net命名空间下 /// 作者:周公 /// 日期:2008-08-08 /// 首发地址:http://blog.csdn.net/zhoufoxcn /// </summary> public class SendMail2 { public SendMail2() { } /// <summary> /// 发送邮件 /// </summary> /// <param name="to">收件人邮件地址</param> /// <param name="from">发件人邮件地址</param> /// <param name="subject">邮件主题</param> /// <param name="body">邮件内容</param> /// <param name="username">登录smtp主机时用到的用户名,注意是邮件地址'@'以前的部分</param> /// <param name="password">登录smtp主机时用到的用户密码</param> /// <param name="smtpHost">发送邮件用到的smtp主机</param> public void Send(string to, string from, string subject, string body, string userName, string password, string smtpHost) { MailAddress from = new MailAddress(from); MailAddress to = new MailAddress(to); MailMessage message = new MailMessage(from, to); message.Subject = subject;//设置邮件主题 message.IsBodyHtml = true;//设置邮件正文为html格式 message.Body = body;//设置邮件内容 SmtpClient client = new SmtpClient(smtpHost); [color=#FF0000] //设置发送邮件身份验证方式 //注意如果发件人地址是abc@def.com,则用户名是abc而不是abc@def.com [/color] client.Credentials = new NetworkCredential(userName, password); client.Send(message); } }