asp.net发邮件的几种方法汇总
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Mail;
using System.Text;
public class SendMail
...{
public SendMail()
...{
}
private string _host;
/**////
/// 服务器地址
///
public string Host
...{
get ...{ return _host; }
set ...{ _host = value; }
}
private int _port;
/**////
/// 服务器端口
///
public int Port
...{
get ...{ return _port; }
set ...{ _port = value; }
}
private string _smtpUsername;
/**////
/// 发送人邮箱用户名
///
public string SmtpUsername
...{
get ...{ return _smtpUsername; }
set ...{ _smtpUsername = value; }
}
private string _sendemail;
/**////
/// 发送人邮箱帐号(只接收加密串,发邮件时解密)
///
public string SendEmail
...{
get
...{
return _sendemail;
}
set ...{ _sendemail = value; }
}
private string _replyToEmail;
/**////
/// 回复人邮箱账号
///
public string ReplyToEmail
...{
get ...{ return _replyToEmail; }
set ...{ _replyToEmail = value; }
}
private string _replyUserName;
/**////
/// 回复人用户名
///
public string ReplyUserName
...{
get ...{ return _replyUserName; }
set ...{ _replyUserName = value; }
}
private string _getemail;
/**////
/// 收件人邮箱帐号
///
public string GetEmail
...{
get ...{ return _getemail; }
set ...{ _getemail = value; }
}
private string _smtpPassword;
/**////
/// 发送人邮箱密码(只接收加密串,发邮件时解密)
///
public string SmtpPassword
...{
get ...{ return _smtpPassword; }
set ...{ _smtpPassword = value; }
}
private string _content;
/**////
/// 邮件内容
///
public string Content
...{
get ...{ return _content; }
set ...{ _content = value; }
}
private string _title;
/**////
/// 邮件标题
///
public string Title
...{
get ...{ return _title; }
set ...{ _title = value; }
}
private string[] _cc = null;
/**////
/// 抄送邮箱
///
public string[] cc
...{
get ...{ return _cc; }
set ...{ _cc = value; }
}
private string[] _bcc = null;
/**////
/// 密送邮箱
///
public string[] bcc
...{
get ...{ return _bcc; }
set ...{ _bcc = value; }
}
/**////
///发送邮件
///
///
public bool Send()
...{
try
...{
MailMessage objMailMessage;
objMailMessage = new MailMessage(SendEmail, _getemail, _title, _content);
if (!string.IsNullOrEmpty(_replyToEmail) && !string.IsNullOrEmpty(_replyUserName))
...{
MailAddress reply = new MailAddress(_replyToEmail, _replyUserName);
objMailMessage.ReplyToList.Add(reply);
}
objMailMessage.BodyEncoding = Encoding.GetEncoding(936);
objMailMessage.IsBodyHtml = true;
if (cc != null && cc.Length > 0)
...{
foreach (string ccAddress in cc)
...{
objMailMessage.CC.Add(new MailAddress(ccAddress));
}
}
if (bcc != null && bcc.Length > 0)
...{
foreach (string bccAddress in bcc)
...{
objMailMessage.Bcc.Add(new MailAddress(bccAddress));
}
}
SmtpClient client = new SmtpClient(this._host, this._port);
if (!String.IsNullOrEmpty(this.SmtpUsername) && !String.IsNullOrEmpty(this.SmtpPassword))
...{
client.Credentials = new NetworkCredential(this.SmtpUsername, this.SmtpPassword);
}
client.EnableSsl = false;
client.Send(objMailMessage);
objMailMessage.Dispose();
return true;
}
catch
...{
return false;
}
}
}
- .NET Core系列之MemoryCache 初识
- 007手机一键Root(安机网一键Root) v3.0 官方最新版 一键ROOT您的Android手机
- 12306密码被盗了怎么办?12306密码外泄解决方法
- 12个字的qq网名
- 150M迷你型无线路由器怎么设置?
- 192.168.1.1打不开怎么办?路由器192.168.1.1打不开的原因以及解决办法
- 2011年电子报合订本 电子报 编辑部 中文 PDF版 [84M]
- 2015年1月15日小米新旗舰发布会现场图文直播
- 2016.3.1vivo Xplay5新品发布会现场视频直播 优酷直播
- 2016华为P9发布会视频直播地址 4月15日华为P9国行发布会直播