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);
}