日期:2014-05-18  浏览次数:20454 次

关于邮件群发问题
C# code

    public class MailInfo
    {
        private String _sanderAddress;
        private String _sanderName;
        private String _sanderPwd;
        private List<String> _recieverAddress;
        private String _mailSubject;
        private String _mailBody;
        private Attachment _mailAttachment;

        /// <summary>
        /// 附件
        /// </summary>
        public Attachment MailAttachment
        {
            get { return _mailAttachment; }
            set { _mailAttachment = value; }
        }
        /// <summary>
        /// 邮件主体
        /// </summary>
        public String MailBody
        {
            get { return _mailBody; }
            set { _mailBody = value; }
        }
        /// <summary>
        /// 邮件标题
        /// </summary>
        public String MailSubject
        {
            get { return _mailSubject; }
            set { _mailSubject = value; }
        }
        /// <summary>
        /// 接收者地址
        /// </summary>
        public List<String> RecieverAddress
        {
            get { return _recieverAddress; }
            set { _recieverAddress = value; }
        }
        /// <summary>
        /// 发送者密码
        /// </summary>
        public String SanderPwd
        {
            get { return _sanderPwd; }
            set { _sanderPwd = value; }
        }
        /// <summary>
        /// 发送者名称
        /// </summary>
        public String SanderName
        {
            get { return _sanderName; }
            set { _sanderName = value; }
        }
        /// <summary>
        /// 发送者地址
        /// </summary>
        public String SanderAddress
        {
            get { return _sanderAddress; }
            set { _sanderAddress = value; }
        }
    }

自定义实体类

C# code

protected static void sendMail(Object obj)
        {
            MailInfo mi = (MailInfo)obj;
            for (int i = 0; i < mi.RecieverAddress.Count; i++)
            {
                MailMessage msg = new MailMessage();
                msg.To.Add(new MailAddress(mi.RecieverAddress[i]));
                msg.From = new MailAddress(mi.SanderAddress);
                msg.Subject = mi.MailSubject;
                msg.Body = mi.MailBody;
                msg.BodyEncoding = System.Text.Encoding.UTF8;
                msg.SubjectEncoding = System.Text.Encoding.UTF8;
                msg.IsBodyHtml = false;
                msg.Priority = MailPriority.High;

                if (mi.MailAttachment != null)
                { msg.Attachments.Add(mi.MailAttachment); }

                SmtpClient client = new SmtpClient();
                client.Host = "smtp.sina.com.cn";
                client.UseDefaultCredentials = false;
                NetworkCredential basicAuthenticationInfo = new NetworkCredential(mi.SanderName, mi.SanderPwd);
                client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                client.Credentials = basicAuthenticationInfo;

                try
                { client.Send(msg); }
                catch (Exception ex)
                { Console.WriteLine(ex.Message); }
            }
        }

发送邮件的方法,通过线程调用

问题:1,有时抛出异常,"邮件发送失败"
  2,有时邮件发送出去了,但邮箱收不到
  3,有时操作系统直接报错:WebDev.WebServer.exe 遇到问题需要关闭。我们对此引起的不便表示抱歉

求解...

------解决方案--------------------
这和你的邮件服务器设置有关..