.net发送邮件实现代码
程序员文章站
2022-06-30 20:55:21
mailmessage objmail = new mailmessage(); objmail.subject = "邮件主题"; objmail.body = "邮件正...
mailmessage objmail = new mailmessage();
objmail.subject = "邮件主题";
objmail.body = "邮件正文";
string mfrom = txtfrom.value; //从页面读取发送者地址
objmail.from = new mailaddress(mfrom);
string mt = txtto.value; //从页面读取接收者地址
mailaddress ma = new mailaddress(mt);
objmail.to.add(ma);
objmail.isbodyhtml = true;//指示邮件为html格式的值
objmail.priority = mailpriority.high;//设置邮件的优先级
objmail.attachments.add(new attachment("f:\\aba.doc"));//添加附件
smtpclient smtp = new smtpclient();
smtp.host = "……"//smtp事务的ip地址,如smtp.cc.com
smtp.send(objmail);//发送邮件
objmail.subject = "邮件主题";
objmail.body = "邮件正文";
string mfrom = txtfrom.value; //从页面读取发送者地址
objmail.from = new mailaddress(mfrom);
string mt = txtto.value; //从页面读取接收者地址
mailaddress ma = new mailaddress(mt);
objmail.to.add(ma);
objmail.isbodyhtml = true;//指示邮件为html格式的值
objmail.priority = mailpriority.high;//设置邮件的优先级
objmail.attachments.add(new attachment("f:\\aba.doc"));//添加附件
smtpclient smtp = new smtpclient();
smtp.host = "……"//smtp事务的ip地址,如smtp.cc.com
smtp.send(objmail);//发送邮件