第一种:
1、配置文件(Web.config) + 少量C#代码
在 configuration 节点下添加
<system.net> <mailSettings> <smtp from="baidu@163.com"> <network host="smtp.163.com" password="baidu" port="25" userName="baidu" defaultCredentials="false"/> </smtp> </mailSettings> </system.net>
/// <summary>
/// 发送邮件/// </summary>private void SendMail(){ System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); message.From = new System.Net.Mail.MailAddress("baidu@163.com");//发送人邮箱地址,与smtp节点中的from值一致 message.To.Add(new System.Net.Mail.MailAddress("taobao@163.com"));//接收人邮箱地址 message.Subject = "hello"; message.Body = "<b>taobao</b>"; message.IsBodyHtml = true; System.Net.Mail.SmtpClient smtpclient = new System.Net.Mail.SmtpClient(); smtpclient.Send(message);}
好,介绍完第一种发送邮件的方法,下面看第二种。
/// <summary>
/// 发送邮件/// </summary>private void SendMail(){ System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); message.From = new System.Net.Mail.MailAddress("baidu@163.com");//发送人邮箱地址,与smtp节点中的from值一致 message.To.Add(new System.Net.Mail.MailAddress("taobao@163.com"));//接收人邮箱地址 message.Subject = "hello"; message.Body = "<b>taobao</b>"; message.IsBodyHtml = true; System.Net.Mail.SmtpClient smtpclient = new System.Net.Mail.SmtpClient("smtp.163.com", 25); smtpclient.Credentials = new System.Net.NetworkCredential("baidu", "baidu");//参数分别是邮箱用户名和密码 smtpclient.Send(message);}
相关文章
- .NET Core(C#)使用WebView2 执行GET和POST请求的方法
- .NET 7(C#)配置使用log4net日志框架的方法
- C#实现发送邮件的三种方法
- [转载]C#中使用ADO.NET连接SQL Server数据库,自动增长字段用作主键,处理事务时的基本方法
- C# .net 使用 SmtpClient 发邮件 ,发送邮箱的配置
- .net 反射访问私有变量和私有方法 如何创建C# Closure ? C# 批量生成随机密码,必须包含数字和字母,并用加密算法加密 C#中的foreach和yield 数组为什么可以使用linq查询 C#中的 具名参数 和 可选参数 显示实现接口 异步CTP(Async CTP)为什么那样工作? C#多线程基础,适合新手了解 C#加快Bitmap的访问速度 C#实现对图片文件的压
- .NET/C# 使用反射调用含 ref 或 out 参数的方法
- 记一次邮件推送的坑,c#基于smtp使用腾讯企业邮箱发送邮件总是失败的原因
- 使用System.Net.Mail中的SMTP发送邮件(带附件) - 大肖
- 使用System.Net.Mail中的SMTP发送邮件(带附件)