SmtpMail类发送邮件实例(调试通过)

一 SmtpMail类发送邮件简单实例
核心代码:
using System.Web.Mail;
private void Button1_Click(object sender, System.EventArgs e)
  {//邮件发送
   if(Page.IsValid==true)
   {
    string to2,from2,topic2,content2;
    to2=to.Text;
    from2=from.Text;
    topic2=topic.Text;
    content2=content.Text;
    try
    {
     //SmtpMail.SmtpServer="smtp.mail.com";//设置SMTP服务器
     SmtpMail.Send(from2,to2,topic2,content2);
     Response.Write("发送成功!");
    }
    catch(Exception ex)
    {
     Response.Write("出现异常,发送失败!");
     Response.Write(ex.ToString());
    }
   }
  }

二 SmtpMail类发送邮件高级实例
核心代码:
using System.Web.Mail;
private void Button1_Click(object sender, System.EventArgs e)
  {//发送邮件程式
   if(Page.IsValid==true){
    string to2,from2,cc2,bcc2,topic2,bodyformail2,prority2,content2;
    to2=to.Text;
    from2=from.Text;
    cc2=cc.Text;
    bcc2=bcc.Text;
    topic2=topic.Text;
    bodyformail2=bodyformail.SelectedItem.Value;
    prority2=prority.SelectedItem.Value;
    content2=content.Text;
    MailMessage mm=new MailMessage();
    mm.From=from2.ToString();
    mm.To=to2.ToString();
    mm.Cc=cc2.ToString();
    mm.Bcc=bcc2.ToString();
    mm.Subject=topic2.ToString();
    mm.Priority=(MailPriority)prority.SelectedIndex;
    //mm.BodyEncoding="Gb2312"//邮件的编码方式
    mm.BodyFormat=(MailFormat)bodyformail.SelectedIndex;
    mm.Body=content2.ToString();
    try{
     SmtpMail.Send(mm);
     Response.Write("发送成功!");
    }
    catch(Exception ex){
     Response.Write(ex.ToString());
    }
   }
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值