但垃圾信太多小心被封了哈!!
1.web.config要加下面這段
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network defaultCredentials="false" host="msa.hinet.net" port="25"/>
</smtp>
</mailSettings>
</system.net>
2.收件人的格式為
<abc@gmail.com> ,<def@gmail.com> ,
3.使用時要new出來喔
PublicClass Class = new PublicClass();//假如這function放在PublicClass裡時
Class.SendByMail(收件人,標題,內文, 寄件人會顯示的標題, 寄件的Email);
4.Function
/// <summary>
/// 用Client寄信 需New出來
/// </summary>
/// <param name="pMail">收件者可以,分格寄多人</param>
/// <param name="pSubject">信件標題</param>
/// <param name="pBody">信件內容</param>
/// <param name="pFromMailName">寄件人會顯示的標題</param>
/// <param name="pFromMail">寄件的Email</param>
public void SendByMail(string pMail, string pSubject, string pBody, string pFromMailName, string pFromMail)
{
System.Net.Mail.MailMessage Mail = new System.Net.Mail.MailMessage();
Mail.From = new System.Net.Mail.MailAddress(pFromMail, pFromMailName);
Mail.Subject = pSubject;
Mail.IsBodyHtml = true;
Mail.BodyEncoding = System.Text.Encoding.UTF8;
Mail.SubjectEncoding = System.Text.Encoding.UTF8;
Mail.Body = pBody;
//這邊多人可以回圈
char[] delimiterChars = { ',' };
string[] words = pMail.Split(delimiterChars);
foreach (string s in words)
{
if (s.Trim() != "")
{
Mail.To.Add(s);
}
}
System.Net.Mail.SmtpClient SMTPServer = new System.Net.Mail.SmtpClient(System.Web.Configuration.WebConfigurationManager.AppSettings["SmtpHost"]);
SMTPServer.Send(Mail);
System.Threading.Thread.Sleep(5);
GC.Collect();
GC.WaitForPendingFinalizers();
}
沒有留言:
張貼留言