Exemple #1
0
        public virtual void SendEmailWithDefaultSender(EmailMessage emailMessage, bool ignoreErrors)
        {
            MailCredentials credentials = new MailCredentials {
                Host         = (string)SysSettings.GetValue(UserConnection, "SmtpHost"),
                Port         = int.Parse(SysSettings.GetValue(UserConnection, "SmtpPort").ToString()),
                UseSsl       = (bool)SysSettings.GetValue(UserConnection, "SmtpEnableSsl"),
                UserName     = (string)SysSettings.GetValue(UserConnection, "SmtpUserName"),
                UserPassword = (string)SysSettings.GetValue(UserConnection, "SmtpUserPassword")
            };

            string[] to = emailMessage.To.ToArray();
            EmailAddressCollection cc  = GetEmailAddressCollection(emailMessage.Cc);
            EmailAddressCollection bcc = GetEmailAddressCollection(emailMessage.Bcc);
            var         smtpClient     = new SmtpClient(UserConnection);
            MailMessage mailBeeMessage = smtpClient.CreateMessage(emailMessage.Body, emailMessage.Subject, to,
                                                                  credentials.UserName, true, new Dictionary <Guid, Tuple <byte[], string> >(0));

            mailBeeMessage.Cc       = cc;
            mailBeeMessage.Bcc      = bcc;
            mailBeeMessage.Priority = (MailPriority)emailMessage.Priority;
            try {
                smtpClient.SendMessage(mailBeeMessage, credentials);
            } catch (Exception e) {
                _log.Error(e);
                if (!ignoreErrors)
                {
                    throw;
                }
            }
        }