c#如何發郵件?
2024-07-21 02:19:16
供稿:網友
本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。easy, too easy;
--------------------code---------------------
private void sengmill_net()
{//.net smtp類進行郵件發送,支持認證,附件添加;
system.web.mail.mailmessage mailmsg = new system.web.mail.mailmessage();
mailmsg.from = this.tb_from.text.trim();
mailmsg.to = this.tb_to.text.trim();
mailmsg.body = this.tb_mailbody.text.trim();
mailmsg.subject = "test mail from hz";
/* 附件的粘貼, ^_^,笨了點;
if(this.att1.value.tostring().trim()!=string.empty)
mailmsg.attachments.add(new system.web.mail.mailattachment(this.att1.value.tostring().trim()));
if(this.att2.value.tostring().trim()!=string.empty)
mailmsg.attachments.add(new system.web.mail.mailattachment(this.att2.value.tostring().trim()));
if(this.att3.value.tostring().trim()!=string.empty)
mailmsg.attachments.add(new system.web.mail.mailattachment(this.att3.value.tostring().trim()));
*/
mailmsg.fields.add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//是否需要驗證,一般是要的
mailmsg.fields.add
("http://schemas.microsoft.com/cdo/configuration/sendusername", "gallon_han");
//自己郵箱的用戶名
mailmsg.fields.add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "218500");
//自己郵箱的密碼
system.web.mail.smtpmail.smtpserver = this.tb_smtpserver.text.trim();
system.web.mail.smtpmail.send(mailmsg);
}