ado,net发送邮件

来源:互联网 发布:淘宝运营投资计划表 编辑:程序博客网 时间:2024/06/05 11:39

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net;
using System.Text;


public partial class SendE_mail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string str_user = this.TextBox1.Text;
        string str_lxfs = this.TextBox2.Text;
        string str_nr = this.TextBox3.Text;
        string sent_body = "姓名:" + str_user + "</br>";
        sent_body+="联系方式:"+str_lxfs+"</br>";
        sent_body += "</br>内容:" + str_nr;
        MailMessage mail = new MailMessage("haitaoDoit@163.com", "993887459@qq.com");

        mail.SubjectEncoding = Encoding.UTF8;
        mail.Subject = "你好";    //设置邮件的主题行
        mail.IsBodyHtml = true;//是否允许内容为 HTML 格式
        mail.BodyEncoding = Encoding.UTF8;
        mail.Body = sent_body;
        SmtpClient smtp = new SmtpClient("smtp.163.com");//不同的邮箱smtp不同,网易的是这个
       
        smtp.Credentials = new NetworkCredential("a","b"); //SMTP验证 //"a"代表用户名 "b"代表密码
        smtp.Send(mail);
        this.Label1.Text = "邮件发送成功";
        mail.Attachments.Dispose();//邮件发送完毕,释放对附件的锁定
    }
}

原创粉丝点击