http://CC318.com

一个程序的窝

我的窝窝 http://CC318.com 这里有更多内容,不信你试试.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

asp.net 2.0 SMTP 发送邮件

Posted on 2009-02-13 11:25  chaoliu  阅读(154)  评论(0编辑  收藏  举报
public void Sender(MailMessage msg)
    {
        smtp = this.ExecuteScalar("select smtp from config").Trim();
        uname = this.ExecuteScalar("select username from config").Trim() ;
        pwd = this.ExecuteScalar("select password from config").Trim();

        SmtpClient sc = new SmtpClient(smtp);
        sc.UseDefaultCredentials = false;
        sc.Credentials = new System.Net.NetworkCredential(uname, pwd);
        sc.DeliveryMethod = SmtpDeliveryMethod.Network;
        sc.Send(msg);
    }
    /// <summary>
    /// 打包成完整邮件
    /// </summary>
    /// <param name="result">查询语句</param>
    /// <param name="to">收信人地址</param>
    public void Msg(string result,string to)
    {
        ufrom = this.ExecuteScalar("select ufrom from config").Trim();
        webname = this.ExecuteScalar("select webname from config");

        string subj = webname + "-" + DateTime.Now.ToShortDateString() + "Bid Info";
        string bod = EnHtml(result);
        MailMessage mm = new MailMessage(ufrom, to, subj, bod);
        mm.IsBodyHtml = true;

        Sender(mm);
    }
http://CC318.com