vs2003 和vs2005下的傳送SMTP郵件 (downmoon原創)
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow
也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!
vs2003 和vs2005下的傳送SMTP郵件 (downmoon原創)
一、vs2003
引用 System.Web.Mail名稱空間
... {
MailMessage mailObj = new MailMessage();
mailObj.To = this.txtTo.Text;
mailObj.From
mailObj.Subject = "精采笑話";
mailObj.Body = "豬!你已中毒! 哈哈 ";
mailObj.BodyFormat
mailObj.BodyEncoding = MailFormat.Base64;
mailObj.Priority = MailPriority.High;
mailObj.Attachments.Add(new MailAttachment("c:/swf/000.bmp"));
SmtpMail.Send(mailObj);
Response.Write("傳送郵件成功!");
}
二、vs2005
引用 System.Net.Mail名稱空間,安全性得到了增強
public static void SendWebMailAndAttach( string server)
{
string file = " e:/inetpub/wwwroot/Test2005All/TestXML/testXML.xml " ;
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage( " [email protected] " , " [email protected] " , " text message for you. " , " Test Title " );
System.Net.Mail.Attachment data = new System.Net.Mail.Attachment(file, System.Net.Mime.MediaTypeNames.Application.Octet);
System.Net.Mime.ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
message.Attachments.Add(data);
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(server);
client.Credentials = new NetworkCredential( " 使用者名稱 " , " 密碼 " );
client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;//這句是關鍵
client.Send(message);
data.Dispose();
}
引用示例
SendWebMailAndAttach("smtp.126.com");