发送邮件(遵循smtp协议即简单的邮件发送协议)

HandleSendEmail.aspx逻辑

 

  protected void Page_Load(object sender,EventArgs e)

  {

    foreach(var item in Request.Form.Keys)

    {

      if(item.ToString().StartsWidth("txtMail"))

      {

        string mail=Request.Form[item.ToString()];

        //设置smtp服务器和端口

        SmtpClient smtpclient=new SmtpClient("smtp@qq.com",25);

        //设置发送邮件时登录smtp服务的用户名和密码

        smtpclient.Credentials=new NetWorkCredentail("用户名","密码");

        MailMessage mailMessage=new MailMessage();

        //设置邮件主题

        mailMessage.Subject="主题";

        mailMessage.Body="内容";//内容

        mailMessage.Form=new MailAddress("发信人邮件地址");//发件人地址

        mailMessage.To.Add(email);//收件人

        

        mailMessage.cc.Add("抄送人邮箱地址");//设置抄送人地址

        //Attachment attachFile=new Attachment(@"附件绝对路径");//附件

        //mailMessage.Attachments.Add(attachFile);

        smtpClient.Send(mailMessage);//执行发送命令

      }

    }

  }

posted @ 2015-08-05 17:48  如此低调的男人  阅读(556)  评论(0编辑  收藏  举报