SmtpClient发送邮件(用户找回密码)
2011-01-06 12:18
507 查看
/// <summary>
/// 利用.Net自带类(SmtpClient) 发送邮件
/// </summary>
/// <param name="stmpserver">邮件服务器</param>
/// <param name="username">用户名(邮箱名称)</param>
/// <param name="pwd">密码</param>
/// <param name="strfrom">发件人</param>
/// <param name="strto">收件人</param>
/// <param name="subject">主题</param>
/// <param name="body">内容</param>
/// <param name="Mulitaddress">发送多人 收件人的邮箱地址以逗号隔开</param>
/// <param name="attachmentName">发送的附件名称 没有附件则为null or ""</param>
public static void SendEmailToUser(string stmpserver, string Mulitaddress, string attachmentName, string username,string pwd,string strfrom,string strto,string subject,string body)
{
SmtpClient smtp = new SmtpClient();
//发送邮件的方式
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
//指定邮件服务器
smtp.Host = stmpserver;
smtp.Port = 587;//Gmail QQ stmp ssl加密使用的端口
smtp.EnableSsl = true;//经过ssl加密
//验证发件人的身份 用户名(邮件地址和密码)
smtp.Credentials = new System.Net.NetworkCredential(username, pwd);
//初始化信息(来自 接收人)
MailMessage _mailmessage = new MailMessage(strfrom, strto);
//发送多个人 接收人邮件地址以,隔开
if (!string.IsNullOrEmpty(Mulitaddress))
{
//添加多个收件人 群发
_mailmessage.Bcc.Add(Mulitaddress);
}
//如果发送失败,SMTP 服务器将发送 失败邮件通知
_mailmessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
//优先级
_mailmessage.Priority = MailPriority.High;
//发送主题
_mailmessage.Subject = subject;
//有附件则添加附件
if (!string.IsNullOrEmpty(attachmentName))
{
System.Net.Mail.Attachment attch = new System.Net.Mail.Attachment(attachmentName);
_mailmessage.Attachments.Add(attch);
}
//邮件主题编码
_mailmessage.SubjectEncoding = System.Text.Encoding.UTF8;
//指定发送的格式 (Html)
_mailmessage.IsBodyHtml = true;
//指定发送邮件的编码
_mailmessage.BodyEncoding = System.Text.Encoding.UTF8;
//指定邮件内容
_mailmessage.Body = body;
//发送邮件
try
{
smtp.Send(_mailmessage);
}
catch(Exception ex) {
throw ex;
}
}
//邮件服务器
string smtpserver = DBUtility.GetConfigVariable.GetConfigValue("smtpserver");
//发件人的邮箱名称
string emailuserName = DBUtility.GetConfigVariable.GetConfigValue("emailuserName");
//发件人的邮箱密码
string emailuserpwd = DBUtility.GetConfigVariable.GetConfigValue("emailuserpwd");
//邮箱地址
string emailfrom = DBUtility.GetConfigVariable.GetConfigValue("emailfrom");
//收件人的邮箱地址
string toUser =model.Email;
//附件
//string attachpath = Server.MapPath("pic/20100119020119.gif");
//邮件内容
string bodys = "亲爱的IT数码商城会员:" + model.Username + ":<br />您好!恭喜你己经找回密码";
bodys+="你的密码是<b style="color;red" mce_style="color;red">"+model.Password+"</b>请妥善保管好你的密码!<br/>";
bodys+="你可以通过http://www.ITWeb.cn/UserLogin.aspx/登录你的帐户!尽情享受IT数码城带给你的的乐趣吧!<br/>";
bodys += "你也可以通过:http://www.ITWeb.cn/UpdateUserPwd.aspx/ 修改的你的密码!<br/>";
bodys += "如果有任何疑问请联系管理员:QQ:664618843 Tel:13456946640<br/>";
bodys += "请勿回复此邮件 谢谢合作!";
//发送邮件
DBUtility.SendEmail.SendEmailToUser(smtpserver, null, null, emailuserName, emailuserpwd, "luokuan2010@gmail.com", toUser, "IT数码城用户找回密码", bodys);
/// 利用.Net自带类(SmtpClient) 发送邮件
/// </summary>
/// <param name="stmpserver">邮件服务器</param>
/// <param name="username">用户名(邮箱名称)</param>
/// <param name="pwd">密码</param>
/// <param name="strfrom">发件人</param>
/// <param name="strto">收件人</param>
/// <param name="subject">主题</param>
/// <param name="body">内容</param>
/// <param name="Mulitaddress">发送多人 收件人的邮箱地址以逗号隔开</param>
/// <param name="attachmentName">发送的附件名称 没有附件则为null or ""</param>
public static void SendEmailToUser(string stmpserver, string Mulitaddress, string attachmentName, string username,string pwd,string strfrom,string strto,string subject,string body)
{
SmtpClient smtp = new SmtpClient();
//发送邮件的方式
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
//指定邮件服务器
smtp.Host = stmpserver;
smtp.Port = 587;//Gmail QQ stmp ssl加密使用的端口
smtp.EnableSsl = true;//经过ssl加密
//验证发件人的身份 用户名(邮件地址和密码)
smtp.Credentials = new System.Net.NetworkCredential(username, pwd);
//初始化信息(来自 接收人)
MailMessage _mailmessage = new MailMessage(strfrom, strto);
//发送多个人 接收人邮件地址以,隔开
if (!string.IsNullOrEmpty(Mulitaddress))
{
//添加多个收件人 群发
_mailmessage.Bcc.Add(Mulitaddress);
}
//如果发送失败,SMTP 服务器将发送 失败邮件通知
_mailmessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
//优先级
_mailmessage.Priority = MailPriority.High;
//发送主题
_mailmessage.Subject = subject;
//有附件则添加附件
if (!string.IsNullOrEmpty(attachmentName))
{
System.Net.Mail.Attachment attch = new System.Net.Mail.Attachment(attachmentName);
_mailmessage.Attachments.Add(attch);
}
//邮件主题编码
_mailmessage.SubjectEncoding = System.Text.Encoding.UTF8;
//指定发送的格式 (Html)
_mailmessage.IsBodyHtml = true;
//指定发送邮件的编码
_mailmessage.BodyEncoding = System.Text.Encoding.UTF8;
//指定邮件内容
_mailmessage.Body = body;
//发送邮件
try
{
smtp.Send(_mailmessage);
}
catch(Exception ex) {
throw ex;
}
}
//邮件服务器
string smtpserver = DBUtility.GetConfigVariable.GetConfigValue("smtpserver");
//发件人的邮箱名称
string emailuserName = DBUtility.GetConfigVariable.GetConfigValue("emailuserName");
//发件人的邮箱密码
string emailuserpwd = DBUtility.GetConfigVariable.GetConfigValue("emailuserpwd");
//邮箱地址
string emailfrom = DBUtility.GetConfigVariable.GetConfigValue("emailfrom");
//收件人的邮箱地址
string toUser =model.Email;
//附件
//string attachpath = Server.MapPath("pic/20100119020119.gif");
//邮件内容
string bodys = "亲爱的IT数码商城会员:" + model.Username + ":<br />您好!恭喜你己经找回密码";
bodys+="你的密码是<b style="color;red" mce_style="color;red">"+model.Password+"</b>请妥善保管好你的密码!<br/>";
bodys+="你可以通过http://www.ITWeb.cn/UserLogin.aspx/登录你的帐户!尽情享受IT数码城带给你的的乐趣吧!<br/>";
bodys += "你也可以通过:http://www.ITWeb.cn/UpdateUserPwd.aspx/ 修改的你的密码!<br/>";
bodys += "如果有任何疑问请联系管理员:QQ:664618843 Tel:13456946640<br/>";
bodys += "请勿回复此邮件 谢谢合作!";
//发送邮件
DBUtility.SendEmail.SendEmailToUser(smtpserver, null, null, emailuserName, emailuserpwd, "luokuan2010@gmail.com", toUser, "IT数码城用户找回密码", bodys);
相关文章推荐
- SmtpClient发送邮件(用户找回密码)
- 用户激活和找回密码发送邮件
- spring boot 整合 mail 发送邮件 【用户注册以及找回密码】
- 发送邮件 激活用户或找回密码
- asp.net利用SmtpClient发送邮件
- SmtpClient:邮件发送
- SmtpClient:邮件发送
- wordpress用户账户信息更新、重置密码或账户被删除时发送提示邮件
- 哈哈哈 利用SmtpClient发送邮件
- SmtpClient发送邮件时附件名称乱码 推荐
- Discuz教程之邮件找回密码邮件发送频率修改
- .net System.Net.Mail 之用SmtpClient发送邮件 Demo
- 利用SmtpClient发送邮件
- C# Email邮件发送,功能是密码找回或者重置功能。
- 为用户添加了被删用户的smtp地址,作为备用smtp地址之后发送邮件不可达
- 发送找回密码邮件(个人笔记)
- 哈哈哈 利用SmtpClient发送邮件
- 使用SmtpClient发送邮件
- 利用SmtpClient发送邮件
- 利用System.Net.Mail 的SmtpClient发送邮件