.net发邮件

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.Text;
using System.IO;
using sentmail;

namespace gene.glo
{
    public partial class yujian : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {

        }


        public string ReplaceText(String userName, string ma)
        {

            string path = string.Empty;

            path = HttpContext.Current.Server.MapPath("a.html");

            if (path == string.Empty)
            {
                return string.Empty;
            }
            System.IO.StreamReader sr = new System.IO.StreamReader(path);
            string str = string.Empty;
            str = sr.ReadToEnd();
            str = str.Replace("$Binghe$", binghe);
            str = str.Replace("$House$", house);


            return str;
        }

        protected void btn_Click1(object sender, EventArgs e)
        {
            string sql = "select * from basicinfo";
            System.Data.DataTable dt = DB.getDataTable(sql);
            string sqlad = "select * from addurl";
            System.Data.DataTable da = DB.getDataTable(sqlad);

            int insend = 0;//记录发送邮件成功条数
            int nosend = 0;//记录发送邮件成功条数
            try
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    //string a = dt.Rows[0]["num"].ToString();&& dt.Rows[0]["send"].ToString() =="null"

                    string sql2 = "select * from chkitem where infoid ='" + dt.Rows[i]["num"].ToString() + "'";
                    System.Data.DataTable ds = DB.getDataTable(sql2);
                    if (ds.Rows[0]["baifen"].ToString() != "")
                    {

                        //string sqlsd = "update basicinfo set send =1";
                        //DB.ExecuteSql(sqlsd);
                        Email email = new Email();

                        email.mailFrom = "***@163.com";
                        email.mailPwd = "**123";

                        email.mailSubject = "结果";
                        email.mailBody = ReplaceText(dt.Rows[i]["name"].ToString(), dt.Rows[i]["md5"].ToString());
                       // email.mailBody = "检测人:" + dt.Rows[i]["name"].ToString() + " &nbsp &nbsp查询码:" + dt.Rows[i]["md5"].ToString() + " &nbsp &nbsp页面地址:" + da.Rows[0]["gene"].ToString() + " &nbsp &nbsp对照表:" + da.Rows[0]["biao"].ToString();
                        email.isbodyHtml = true;    //是否是HTML
                        //email.host = "smtp.163.com";//QQ邮箱则:smtp:qq.com,
                        email.host = "smtp.sina.com.cn";//新浪邮箱
                        email.mailToArray = new string[] { dt.Rows[i]["email"].ToString() }; //收件人


                        if (email.Send())
                        {

                            insend++;
                        }
                        else
                        {

                            nosend++;
                        }
                    }

                    else
                    {
                        return;
                    }


                }

                Response.Write(insend + "<script type='text/javascript'>alert('条邮件发送成功!');history.go(-1)</script>");
            }
            catch(Exception ex)
            {
                throw ex;
            }

        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值