Beispiel #1
0
        /// <summary>
        /// Sends a specified e-mail message.
        /// </summary>
        public async Task SendMailAsync(MailMessageDTO message)
        {
            if (From != null)
            {
                message.From = From;
            }
            if (!string.IsNullOrEmpty(SubjectFormatString))
            {
                message.Subject = string.Format(SubjectFormatString, message.Subject);
            }
            if (!string.IsNullOrEmpty(BodyTextFormatString) && !string.IsNullOrEmpty(message.BodyText))
            {
                message.BodyText = string.Format(BodyTextFormatString, message.BodyText);
            }
            if (!string.IsNullOrEmpty(BodyHtmlFormatString) && !string.IsNullOrEmpty(message.BodyHtml))
            {
                message.BodyHtml = string.Format(BodyHtmlFormatString, message.BodyHtml);
            }

            if (OverrideToAddresses != null && OverrideToAddresses.Any())
            {
                message.To.Clear();
                message.Cc.Clear();
                message.Bcc.Clear();

                foreach (var address in OverrideToAddresses)
                {
                    message.To.Add(address);
                }
            }

            var sendingArgs = new MessageSendingEventArgs(message);

            OnMessageSending(sendingArgs);

            if (!sendingArgs.Cancel)
            {
                await sender.SendAsync(sendingArgs.Message);
            }
        }
        /// <summary>
        /// Sends a specified e-mail message.
        /// </summary>
        public void SendMail(MailMessage message)
        {
            if (!string.IsNullOrEmpty(FromAddress))
            {
                message.From = new MailAddress(FromAddress);
            }
            if (!string.IsNullOrEmpty(SubjectFormatString))
            {
                message.Subject = string.Format(SubjectFormatString, message.Subject);
            }
            if (!string.IsNullOrEmpty(GlobalTemplateFormatString))
            {
                message.Body = string.Format(GlobalTemplateFormatString, message.Body);
            }

            if (!string.IsNullOrEmpty(OverrideToAddresses))
            {
                message.To.Clear();
                message.CC.Clear();
                message.Bcc.Clear();

                foreach (var address in OverrideToAddresses.Split(new[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    message.To.Add(address);
                }
            }

            var sendingArgs = new MessageSendingEventArgs(message);

            OnMessageSending(sendingArgs);

            if (!sendingArgs.Cancel)
            {
                sender.Send(sendingArgs.Message);
            }
        }
Beispiel #3
0
 protected virtual void OnMessageSending(MessageSendingEventArgs args)
 {
 }
 protected virtual void OnMessageSending(MessageSendingEventArgs args)
 {
 }
        /// <summary>
        /// Sends a specified e-mail message.
        /// </summary>
        public void SendMail(MailMessage message)
        {
            if (!string.IsNullOrEmpty(FromAddress))
            {
                message.From = new MailAddress(FromAddress);
            }
            if (!string.IsNullOrEmpty(SubjectFormatString))
            {
                message.Subject = string.Format(SubjectFormatString, message.Subject);
            }
            if (!string.IsNullOrEmpty(GlobalTemplateFormatString))
            {
                message.Body = string.Format(GlobalTemplateFormatString, message.Body);
            }

            if (!string.IsNullOrEmpty(OverrideToAddresses))
            {
                message.To.Clear();
                message.CC.Clear();
                message.Bcc.Clear();

                foreach (var address in OverrideToAddresses.Split(new[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    message.To.Add(address);
                }
            }

            var sendingArgs = new MessageSendingEventArgs(message);
            OnMessageSending(sendingArgs);

            if (!sendingArgs.Cancel)
            {
                sender.Send(sendingArgs.Message);
            }
        }