通过SmtpClient
,实现.NET框架下的SMTP邮件协议编程
SMTP - .NET发送邮件
1 example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| using System.Net.Mail;
namespace SMTP { public static class SMTPUtility { public static void SendMail(string mailto, string mailBody, string mailSubject) { MailMessage MyMail = new MailMessage(); MyMail.From = new MailAddress("demo.noreply@cn.demo.com", "System Notification"); MyMail.To.Add(mailto); MyMail.Subject = mailSubject; MyMail.IsBodyHtml = true; MyMail.Body = mailBody;
SmtpClient smtp = new SmtpClient(); smtp.Host = "hostname or IP address"; smtp.Send(MyMail); } } }
|
- 注:
MailMessage
和SmtpClient
通过using System.Net.Mail;
导入namespace。