邮件发送类,支持Gmail
生活随笔
收集整理的這篇文章主要介紹了
邮件发送类,支持Gmail
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
郵件發(fā)送類,支持Gmail,使用簡單方便
using?System;using?System.Collections.Generic;
using?System.Text;
using?System.Net;
using?System.Net.Mail;
namespace?LZ2007.Function
...{
????/**////?<summary>
????///?郵件發(fā)送類
????///?<CreateDate>2007/07/02</CreateDate>
????///?<ModifyDate>2007/07/02</ModifyDate>
????///?<Author>張怡冰</Author>
????///?</summary>
????public?class?Mail
????...{
????????public?Mail(string?host,?int?port,?string?smtpUsername,?string?smtpPassword)
????????...{
????????????_host?=?host;
????????????_port?=?port;
????????????_smtpUsername?=?smtpUsername;
????????????_smtpPassword?=?smtpPassword;
????????}
????????public?Mail()?...{?}
????????private?string?_host;
????????public?string?Host
????????...{
????????????get?...{?return?_host;?}
????????????set?...{?_host?=?value;?}
????????}
????????private?int?_port;
????????public?int?Port
????????...{
????????????get?...{?return?_port;?}
????????????set?...{?_port?=?value;?}
????????}
????????private?string?_smtpUsername;
????????public?string?SmtpUsername
????????...{
????????????get?...{?return?_smtpUsername;?}
????????????set?...{?_smtpUsername?=?value;?}
????????}
????????private?string?_smtpPassword;
????????public?string?SmtpPassword
????????...{
????????????get?...{?return?_smtpPassword;?}
????????????set?...{?_smtpPassword?=?value;?}
????????}
????????public?void?SendMail(string?from,?string?to,?string?subject,?string?body,?bool?ssl,?string[]?cc,?string[]?bcc)
????????...{
????????????//?Create?mail?message
????????????MailMessage?message?=?new?MailMessage(from,?to,?subject,?body);
????????????message.BodyEncoding?=?Encoding.GetEncoding(936);
????????????message.IsBodyHtml?=?true;
????????????if?(cc?!=?null?&&?cc.Length?>?0)
????????????...{
????????????????foreach?(string?ccAddress?in?cc)
????????????????...{
????????????????????message.CC.Add(new?MailAddress(ccAddress));
????????????????}
????????????}
????????????if?(bcc?!=?null?&&?bcc.Length?>?0)
????????????...{
????????????????foreach?(string?bccAddress?in?bcc)
????????????????...{
????????????????????message.Bcc.Add(new?MailAddress(bccAddress));
????????????????}
????????????}
????????????//?Send?email
????????????SmtpClient?client?=?new?SmtpClient(this._host,?this._port);
????????????if?(!String.IsNullOrEmpty(this._smtpUsername)?&&?!String.IsNullOrEmpty(this._smtpPassword))
????????????...{
????????????????client.Credentials?=?new?NetworkCredential(this._smtpUsername,?this._smtpPassword);
????????????}
????????????if?(ssl)
????????????...{
????????????????client.EnableSsl?=?true;
????????????}
????????????client.Send(message);
????????}
????}
}
轉(zhuǎn)載于:https://www.cnblogs.com/eicesoft/archive/2007/08/01/839157.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的邮件发送类,支持Gmail的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: GBase数据库监控
- 下一篇: [转贴]犯贱报(一张浓缩大学生活的..)