如何利用System.Net.Mail类发送EMAIL
生活随笔
收集整理的這篇文章主要介紹了
如何利用System.Net.Mail类发送EMAIL
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
廢話(huà)不多說(shuō),直接上代碼
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Mail;namespace MailSender {class Program{static string strHost = string.Empty;static string strAccount = string.Empty;static string strPwd = string.Empty;static string strFrom = string.Empty;static void Main(string[] args){strHost = "smtp.qq.com"; //STMP服務(wù)器地址strAccount = "xxx@126.com"; //SMTP服務(wù)帳號(hào)strPwd = "123456"; //SMTP服務(wù)密碼strFrom = "xxx@126.com"; //發(fā)送方郵件地址Console.WriteLine(sendMail("cnkker@qq.com", "這是一封測(cè)試郵件", "這是一封測(cè)試郵件的正文內(nèi)容") ? "Success" : "Unsuccess");Console.ReadLine();}/// <summary>/// 發(fā)送郵件/// </summary>/// <param name="to">接收方郵件地址</param>/// <param name="title">郵件標(biāo)題</param>/// <param name="content">郵件正文內(nèi)容</param>/// <returns></returns>/// <author>Jailu</author>/// <date>2007-04-10</date>static bool sendMail(string to, string title, string content){SmtpClient _smtpClient = new SmtpClient();_smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定電子郵件發(fā)送方式_smtpClient.Host = strHost; ;//指定SMTP服務(wù)器_smtpClient.Credentials = new System.Net.NetworkCredential(strAccount, strPwd);//用戶(hù)名和密碼MailMessage _mailMessage = new MailMessage(strFrom, to);_mailMessage.Subject = title;//主題_mailMessage.Body = content;//內(nèi)容_mailMessage.BodyEncoding = System.Text.Encoding.UTF8;//正文編碼_mailMessage.IsBodyHtml = true;//設(shè)置為HTML格式_mailMessage.Priority = MailPriority.High;//優(yōu)先級(jí)try{_smtpClient.Send(_mailMessage);return true;}catch(Exception ex){return false;}}} }
?
轉(zhuǎn)載于:https://www.cnblogs.com/CnKker/archive/2012/01/12/2797524.html
總結(jié)
以上是生活随笔為你收集整理的如何利用System.Net.Mail类发送EMAIL的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: mysql 笔记三
- 下一篇: 在Mono 2.8上部署ASP.NET