1、web.config文件配置,发送方邮箱账号、密码、邮箱类型
2、新建email文件
3、在email文件中填写必要代码
public class Email
{
public const string WEB_SITE = @"http://tasly.chinacloudsites.cn";
//public const string WEB_SITE = @"http://localhost:24295/";
#region发邮件
///<summary>
///发送邮件
///</summary>
///<param name="Email">发送的邮件地址,支持多个用英文;隔开</param>
///<param name="title">标题</param>
///<param name="body">内容</param>
///<returns></returns>
public static bool Send(string Email, string title, string body)
{
try {
string fromUser = System.Configuration.ConfigurationManager.AppSettings["fromUser"];
string password = System.Configuration.ConfigurationManager.AppSettings["password"];
string address = System.Configuration.ConfigurationManager.AppSettings["address"];
//创建MailMessage对象 //在ASP.NET利用本机的SMTP虚拟服务器的SMTP来发送邮件
MailMessage Msg = new MailMessage();//
Msg.From = new MailAddress("\"澳大利亚中医药学会官网\"<"+fromUser +">");
foreach (var item in Email.Split( ';' ))
{
Msg.To.Add(item);
}
Msg.Subject = title;
//邮件的主题
Msg.IsBodyHtml =true;
//指示邮件正文是否采用HTML文件格式.
Msg.Body = body;
//邮件内容
SmtpClient objEmail = new SmtpClient(address);
//SMTP服务器主机名,比如GMail的smtp.gmail.com
objEmail.Credentials = new NetworkCredential (fromUser, password);
//objEmail.Timeout = 30000;
objEmail.EnableSsl = true ;
//是否启用加密连接,GMail的邮箱必须用加密,其他不支持的邮箱用false
objEmail.Send(Msg);
return true ;
}
catch(Exception e)
{
return false;
}
}