在Asp.net中发Email

try
{
    //引入相关空间
    //using System.Net;
    //using System.Net.Mail;

    MailMessage mail = new MailMessage("[email protected]", "xxxxxx@126.com");  //("发送方邮件地址", "接收方邮件地址");
    mail.SubjectEncoding = System.Text.Encoding.UTF8;
    mail.Subject = "from 163";  //邮件标题
    mail.IsBodyHtml = true; //是否允许内容为 HTML 格式
    mail.BodyEncoding = System.Text.Encoding.UTF8;
    mail.Body = "<strong>ha,this is from 163</strong>";
    mail.CC.Add("xxxxxx@126.com");  //抄送
    mail.Bcc.Add("xxxxxx@163.com");//密送
    mail.Attachments.Add(new Attachment(Server.MapPath("Temp_Email.aspx"))); //添加一个附件

    SmtpClient smtp = new SmtpClient("smtp.163.com"); //SMTP 服务器地址(smtp是简单邮件传输协议, 用于电子邮件的传输)   (pop用于接收email)
    smtp.Credentials = new NetworkCredential("xgwsy", "xgwsy163"); //SMTP 验证
    smtp.Send(mail);

    mail.Attachments.Dispose(); //邮件发送完毕,释放对附件的锁定
    Response.Write("ok");
}
catch (Exception ex)
{
    Response.Write(ex.Message);
}

你可能感兴趣的:(html,.net,asp.net,asp)