c#使用netmail方式发送邮件示例
/// <summary>
/// netmail方式测试通过
/// </summary>
private void testsend()
{
system.net.mail.mailmessage mm = new system.net.mail.mailmessage();
//收件人地址
mm.to.add(new system.net.mail.mailaddress("xxxxxx@163.com", "name"));
//发件人地址
mm.from = new system.net.mail.mailaddress("xxxxx@sina.com");
//这个可以不指定
//mm.sender = new system.net.mail.mailaddress("xxx@sina.com", "sendername");、
mm.subject = "this is test email";
mm.body = "<h3>this is testing smtp mail send by me</h3>";
mm.isbodyhtml = true;
mm.priority = system.net.mail.mailpriority.high; // 设置发送邮件的优先级
system.net.mail.smtpclient smtcliend = new system.net.mail.smtpclient();
//指定邮件服务器
smtcliend.host = "smtp.sina.com";
//smtp邮件服务器的端口号
smtcliend.port = 25;
//设置发件人邮箱的用户名和地址,使用公共邮件服务器一般需要提供,不然发送不会成功
smtcliend.credentials = new networkcredential("xxxxxxx", "xxxxxxx");
//指定邮件的发送方式
smtcliend.deliverymethod = system.net.mail.smtpdeliverymethod.network;
try
{
smtcliend.send(mm);
}
catch (system.net.mail.smtpexception ex)
{
response.write(ex.message);
}
catch (exception ex)
{
response.write(ex.message);
}
}