ASP.NET发送邮件
来源:互联网 发布:明星上镜和真人知乎 编辑:程序博客网 时间:2024/09/21 09:01
由于需要在Starlight Portal中提供邮件发送功能,所以在网上找了一些asp.net中发送邮件的文章,可是都不能满足需求。因为大部分的文章都介绍得很简单,只是告诉你怎么用MailMessage,而我想用Gmail的邮箱发送信件,因此会碰到一些额外的问题,比如:
- Gmail的Smtp端口不是默认的25,而是465
- Gmail的Smtp采用的是SSL连接
因此,要发送邮件,就必须解决这两个问题,其他的基本问题都可以很容易的找到解决方法。在这里记下代码,以供大家使用。
MailMessage msg = new MailMessage();
msg.From = settings.SystemEmailAccount;
msg.To = to;
msg.Subject = subject;
msg.Body = body;
if(settings.SmtpAuthenticationRequired)
{
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1" );
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", settings.SystemEmailAccount);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", settings.SystemEmailAccountPassword);
}
if(settings.SmtpPort != 25)
{
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", settings.SmtpPort.ToString());
}
if(settings.SmtpUseSSL)
{
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "1");
}
SmtpMail.SmtpServer = settings.SmtpServer;
SmtpMail.Send(msg);
- asp.net发送邮件
- ASP.NET发送邮件
- asp.net发送邮件
- asp.net发送邮件
- Asp.net发送邮件
- asp.net 发送邮件
- asp.net 发送邮件
- asp.net邮件发送
- asp.net 邮件发送
- asp.net发送邮件
- ASP.NET发送邮件
- asp.net发送邮件
- asp.net 发送邮件
- asp.net 邮件发送
- asp.net发送邮件
- ASP.NET发送邮件
- asp.net 发送邮件
- asp.net 发送邮件
- 常用js验证说明
- 中国十大网站
- 邮件发送类,支持HTML格式,支持优先级设置
- DockPanel布局
- 添加域后如何将域用户加入本地管理员组
- ASP.NET发送邮件
- 我的BSP分割原始数据和结果格式(基本分割+Portal)
- 无聊
- 字符串与二进制数之间的互相转换
- 30余个CSS导航菜单效果
- .NET中管理数字证书(Digital Certificate)的一些类
- 期末考试,还有最后一门了!!
- JS特效
- CSS手册