Beispiel #1
0
        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="info">接收人信息 Mafly.Mail.MailInfo </param>
        /// <param name="message">默认为null。 System.Net.Mail.MailMessage </param>
        public void Send(MailInfo info, MailMessage message = null)
        {
            var sender = new SmtpClient();

            message = message ?? new MailMessage();
            if (string.IsNullOrEmpty(info.ReceiverName))
            {
                info.ReceiverName = info.Receiver;
            }
            if (info.Receiver.Contains(","))
            {
                message.To.Add(info.Receiver);
            }
            else
            {
                message.To.Add(new MailAddress(info.Receiver, info.ReceiverName));
            }

            message.Subject = info.Subject;
            if (!string.IsNullOrEmpty(info.Replay))
            {
                message.ReplyToList.Add(new MailAddress(info.Replay));
            }
            message.Body = info.Body;
            if (!string.IsNullOrEmpty(info.CC))
            {
                message.CC.Add(new MailAddress(info.CC));
            }
            try
            {
                message.IsBodyHtml           = mailConfig.IsHtml;
                message.From                 = new MailAddress(mailConfig.From, mailConfig.DisplayName);
                sender.Host                  = mailConfig.Host;
                sender.Port                  = mailConfig.Port;
                sender.UseDefaultCredentials = false;
                sender.Credentials           = new NetworkCredential(mailConfig.User, mailConfig.Password);
                sender.DeliveryMethod        = SmtpDeliveryMethod.Network;
                sender.EnableSsl             = mailConfig.EnableSsl;
                sender.Send(message);
            }
            catch
            {
                message.From                 = new MailAddress("*****@*****.**", "NuGet_Mafly");
                message.IsBodyHtml           = true;
                sender.Host                  = "smtp.163.com";
                sender.Port                  = 25;
                sender.UseDefaultCredentials = false;
                sender.Credentials           = new NetworkCredential("*****@*****.**", "vzihlbquwnriqlht");
                sender.DeliveryMethod        = SmtpDeliveryMethod.Network;
                sender.EnableSsl             = false;
                sender.Send(message);
                //throw new Team.Common.Exceptions.EmailConfigurationException { Status = Team.Common.Enums.EmailConfiguration.ConfigurationError };
            }
            // sender.Send(message);
        }
Beispiel #2
0
        /// <summary>
        /// 发送邮件(带附件)
        /// </summary>
        /// <param name="info">接收人信息 Mafly.Mail.MailInfo </param>
        /// <param name="attachments">附件列表 System.Net.Mail.Attachment </param>
        public void Send(MailInfo info, params Attachment[] attachments)
        {
            var message = new MailMessage();

            foreach (var item in attachments)
            {
                message.Attachments.Add(item);
            }
            try
            {
                Send(info, message);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #3
0
        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="info">接收人信息 Mafly.Mail.MailInfo </param>
        /// <param name="mailConfig">发件邮箱配置</param>
        /// <param name="message">默认为null。 System.Net.Mail.MailMessage </param>
        /// <param name="isSingleSend">是否群发单显。当邮件接收人为多个时,可选择该模式,即可对多个收件人分别发送,收件方不会知道这封邮件有多个收件人</param>
        protected void Send(MailInfo info, MailConfig mailConfig, MailMessage message = null, bool isSingleSend = false)
        {
            message         = message ?? new MailMessage();
            message.Subject = info.Subject;
            if (!string.IsNullOrEmpty(info.Replay))
            {
                message.ReplyToList.Add(new MailAddress(info.Replay));
            }
            message.Body = info.Body;
            if (!string.IsNullOrEmpty(info.CC))
            {
                message.CC.Add(info.CC);
            }

            //群发单显(当邮件接收人为多个时,可选择该模式,即可对多个收件人分别发送,收件方不会知道这封邮件有多个收件人)
            if (isSingleSend && info.Receiver.Contains(","))
            {
                foreach (var item in info.Receiver.Split(','))
                {
                    message.To.Clear();
                    message.To.Add(item);

                    SmtpClientSend(mailConfig, message);
                }
                return;
            }
            else
            {
                if (!isSingleSend && info.Receiver.Contains(","))
                {
                    message.To.Add(info.Receiver);
                }
                else
                {
                    message.To.Add(new MailAddress(info.Receiver, string.IsNullOrEmpty(info.ReceiverName) ? info.Receiver : info.ReceiverName));
                }
            }

            SmtpClientSend(mailConfig, message);
        }
Beispiel #4
0
 /// <summary>
 /// 发送邮件
 /// </summary>
 /// <param name="info">接收人信息 Mafly.Mail.MailInfo </param>
 /// <param name="isSingleSend">是否群发单显</param>
 /// <param name="message">默认为null。 System.Net.Mail.MailMessage </param>
 public void Send(MailInfo info, bool isSingleSend, MailMessage message = null)
 {
     base.Send(info, mailConfig, message, isSingleSend);
 }
Beispiel #5
0
 /// <summary>
 /// 发送邮件
 /// </summary>
 /// <param name="info">接收人信息 Mafly.Mail.MailInfo </param>
 /// <param name="message">默认为null。 System.Net.Mail.MailMessage </param>
 public void Send(MailInfo info, MailMessage message = null)
 {
     base.Send(info, mailConfig, message);
 }
Beispiel #6
0
        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="info">接收人信息 Mafly.Mail.MailInfo </param>
        /// <param name="message">默认为null。 System.Net.Mail.MailMessage </param>
        public void Send(MailInfo info, MailMessage message = null)
        {
            var sender = new SmtpClient();
            message = message ?? new MailMessage();
            if (string.IsNullOrEmpty(info.ReceiverName))
                info.ReceiverName = info.Receiver;
            if (info.Receiver.Contains(","))
                message.To.Add(info.Receiver);
            else
                message.To.Add(new MailAddress(info.Receiver, info.ReceiverName));

            message.Subject = info.Subject;
            if (!string.IsNullOrEmpty(info.Replay))
                message.ReplyToList.Add(new MailAddress(info.Replay));
            message.Body = info.Body;
            if (!string.IsNullOrEmpty(info.CC))
                message.CC.Add(new MailAddress(info.CC));
            try
            {
                message.IsBodyHtml = mailConfig.IsHtml;
                message.From = new MailAddress(mailConfig.From, mailConfig.DisplayName);
                sender.Host = mailConfig.Host;
                sender.Port = mailConfig.Port;
                sender.UseDefaultCredentials = false;
                sender.Credentials = new NetworkCredential(mailConfig.User, mailConfig.Password);
                sender.DeliveryMethod = SmtpDeliveryMethod.Network;
                sender.EnableSsl = mailConfig.EnableSsl;
                sender.Send(message);
            }
            catch
            {
                message.From = new MailAddress("*****@*****.**", "NuGet_Mafly");
                message.IsBodyHtml = true;
                sender.Host = "smtp.163.com";
                sender.Port = 25;
                sender.UseDefaultCredentials = false;
                sender.Credentials = new NetworkCredential("*****@*****.**", "nuget123.");
                sender.DeliveryMethod = SmtpDeliveryMethod.Network;
                sender.EnableSsl = false;
                sender.Send(message);
                //throw new Team.Common.Exceptions.EmailConfigurationException { Status = Team.Common.Enums.EmailConfiguration.ConfigurationError };
            }
            // sender.Send(message);
        }
Beispiel #7
0
 /// <summary>
 /// 发送邮件(带附件)
 /// </summary>
 /// <param name="info">接收人信息 Mafly.Mail.MailInfo </param>
 /// <param name="filePath">附件路径 System.String </param>
 public void Send(MailInfo info, string filePath)
 {
     var message = new MailMessage();
     message.Attachments.Add(new Attachment(filePath));
     Send(info, message);
 }
Beispiel #8
0
 /// <summary>
 /// 发送邮件(带附件)
 /// </summary>
 /// <param name="info">接收人信息 Mafly.Mail.MailInfo </param>
 /// <param name="attachments">附件列表 System.Net.Mail.Attachment </param>
 public void Send(MailInfo info, params Attachment[] attachments)
 {
     var message = new MailMessage();
     foreach (var item in attachments)
     {
         message.Attachments.Add(item);
     }
     try
     {
         Send(info, message);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Beispiel #9
0
        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="info">接收人信息 Mafly.Mail.MailInfo </param>
        /// <param name="message">默认为null。 System.Net.Mail.MailMessage </param>
        public void Send(MailInfo info, MailMessage message = null)
        {
            var sender = new SmtpClient();
            message = message ?? new MailMessage();
            if (string.IsNullOrEmpty(info.ReceiverName))
                info.ReceiverName = info.Receiver;
            if (info.Receiver.Contains(","))
                message.To.Add(info.Receiver);
            else
                message.To.Add(new MailAddress(info.Receiver, info.ReceiverName));

            message.Subject = info.Subject;
            if (!string.IsNullOrEmpty(info.Replay))
                message.ReplyToList.Add(new MailAddress(info.Replay));
            message.Body = info.Body;
            if (!string.IsNullOrEmpty(info.CC))
                message.CC.Add(new MailAddress(info.CC));
            try
            {
                message.IsBodyHtml = mailConfig.IsHtml;
                message.From = new MailAddress(mailConfig.From, mailConfig.DisplayName);
                sender.Host = mailConfig.Host;
                sender.Port = mailConfig.Port;
                sender.UseDefaultCredentials = false;
                sender.Credentials = new NetworkCredential(mailConfig.User, mailConfig.Password);
                sender.DeliveryMethod = SmtpDeliveryMethod.Network;
                sender.EnableSsl = mailConfig.EnableSsl;
                sender.Send(message);
            }
            catch (Exception ex)
            {
                //message.From = new MailAddress("*****@*****.**", "NuGet_Mafly");
                //message.IsBodyHtml = true;
                //sender.Host = "smtp.163.com";
                //sender.Port = 25;
                //sender.UseDefaultCredentials = false;
                //sender.Credentials = new NetworkCredential("*****@*****.**", "vzihlbquwnriqlht");
                //sender.DeliveryMethod = SmtpDeliveryMethod.Network;
                //sender.EnableSsl = false;
                //sender.Send(message);
                throw new Exception("发送邮件失败,错误信息:" + ex.Message + "\r\n" + ex.ToString());
            }
            // sender.Send(message);
        }