最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
stmp发送邮件asp.net实现代码
时间:2022-06-25 06:18:40 编辑:袖梨 来源:一聚教程网
stmp发送邮件asp教程.net实现代码
我们使用SmtpMail类方案能满足大部分基本的发送邮件的功能需求嗾。
public class Mail
{
#region 邮件参数
static public string accountName = System.Configuration.ConfigurationManager.AppSettings["SmtpAccountName"];
static public string password = System.Configuration.ConfigurationManager.AppSettings["SmtpAccountPW"];
static public string smtpServer = System.Configuration.ConfigurationManager.AppSettings["SmtpServer"];
static public int smtpPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["SmtpPort"]);
#endregion///
/// 邮件发送方法一
///
///
///
///
static public void SendMail(string sendTo, string subject, string body)
{
//.net smtp
System.Web.Mail.MailMessage mailmsg = new System.Web.Mail.MailMessage();
mailmsg.To = sendTo;
//mailmsg.Cc = cc;
mailmsg.Subject = subject;
mailmsg.Body = body;
mailmsg.BodyFormat = MailFormat.Html;
//sender here
mailmsg.From = Mail.accountName;
// certify needed
mailmsg.Fields.Add("http://schemas.*mi*c*rosoft.com/cdo/configuration/smtpauthenticate", "1");//1 is to certify
//the user id
mailmsg.Fields.Add(
"http://schemas.*micro*s*oft.com/cdo/configuration/sendusername",
Mail.accountName);
//the password
mailmsg.Fields.Add(
"http://schemas.m*icro*s*oft.com/cdo/configuration/sendpassword",
Mail.password);System.Web.Mail.SmtpMail.SmtpServer = Mail.smtpServer;
System.Web.Mail.SmtpMail.Send(mailmsg);
}
///
/// 邮件发送方法二
///
///
///
///
static public void SendMail2(string sendTo, string subject, string body)
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(accountName, sendTo, subject, body);
msg.From = new System.Net.Mail.MailAddress(accountName, "Mail");
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(smtpServer);
msg.IsBodyHtml = true;
client.Credentials = new System.Net.NetworkCredential(accountName, password);
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;client.Send(msg);
}
}
相关文章
- kimichat官网入口在哪-kimichat官网链接及使用教程 12-14
- 计算机二级考试官网入口-报名通道一键直达 12-14
- 囧次元动漫app下载安装官方正版-囧次元动漫2025最新版本资源免费下载 12-14
- 知到智慧树官网入口在哪 知到智慧树在线登录网页版 12-14
- 苹果中国官网教育优惠通道-苹果官网以旧换新估价入口 12-14
- 污污漫画入口风险警示-合规访问指南与安全指引 12-13