现在的位置: 首页 > 综合 > 正文

使用需要验证用户的smtp服务器发送邮件

2013年10月11日 ⁄ 综合 ⁄ 共 713字 ⁄ 字号 评论关闭

使用需要验证用户的smtp服务器发送邮件
偶尔看到,觉得对某些人还是有用,顺手转了过来....

using System.Web.Mail;
private void Page_Load(object sender, System.EventArgs e)
{
 MailMessage mail = new MailMessage();
 mail.To = "me@mycompany.com";
 mail.From = "you@yourcompany.com";
 mail.Subject = "this is a test email.";
 mail.Body = "Some text goes here";
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here"); //set your username here
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret"); //set your password here

 SmtpMail.SmtpServer = "mail.mycompany.com";  //your real server goes here
 SmtpMail.Send( mail );
}

抱歉!评论已关闭.