using System;
using System.Text;
using System.Net;
using System.Net.Mail;
using BLL.Config;
    /// <summary>
    /// 发送email的类
    /// </summary>
    public class Email
    {
        private string _sendaddress;
        private string _sendname;
        private string _getaddress;
        private string _smtp;
        private string _uid;
        private string _pwd;
        private string _title;
        private string _body;        public Email()
        {
            Config cfg = new Config();
            cfg.Initform();
            this._sendaddress = cfg.email_sendaddress;
            this._pwd = cfg.email_pwd;
            this._smtp = cfg.email_smtp;
            this._uid = cfg.email_uid;
            this._sendname = cfg.email_sendname;        }
        /// <summary>
        /// 收件地址
        /// </summary>
        public string Getaddress
        {
            set { _getaddress = value; }
        }
        /// <summary>
        /// 标题
        /// </summary>
        public string Title
        {
            set { _title = value; }
        }
        /// <summary>
        /// 内容
        /// </summary>
        public string Body
        {
            set { _body = value; }
        }        public bool send()
        {
            try
            {
                //编码暂硬性规定为GB2312 
                Encoding encoding = Encoding.GetEncoding(936);
                MailMessage Message = new MailMessage(
                new MailAddress(_sendaddress, _sendname, encoding),//第一个是发信人的地址,第二个参数是发信人
                new MailAddress(_getaddress));//收信人邮箱
                Message.SubjectEncoding = encoding;
                Message.Subject = _title;//标题
                Message.BodyEncoding = encoding;
                Message.Body = _body; //主体
                SmtpClient smtpClient = new SmtpClient(_smtp);//信箱服务器
                smtpClient.Credentials = new NetworkCredential(_uid, _pwd);//信箱的用户名和密码
                smtpClient.Timeout = 999999;
                smtpClient.Send(Message);
                return true;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
                return false;
            }
        }
    }
为何不能实现自动发邮件

解决方案 »

  1.   

    网站后台添加了自动回复邮件功能,用163  yahoo 新浪的支持smtp的邮箱测试都没有问题,但唯独用万网的企业邮箱添加后,无法实现自动发送邮件,但用电脑的outlook或者live mail 配置了万网的pop3 和smtp后收发都没有问题,咨询了万网,他们说正在查,看是不是主机的支持问题,郁闷,我想问下代码设定的有没有错误。谢谢
      

  2.   

    不是定时,是当有新订单,或新留言,的时候,后台自动发送已经编译好的回复内容到客户留的邮箱里面。
    测试用163或者新浪的 smtp 设定都没有问题,能发送,唯独用万网的企业邮箱无法实现,纠结了2天了,郁闷中
    帮我看看是代码哪里设定的问题吗
    谢谢
      

  3.   

    咨询万网,换JMAIL等其他是否可以