BrockAllen.MembershipReboot.SmtpMessageDelivery.Send C# (CSharp) Метод

Send() публичный Метод

public Send ( Message msg ) : void
msg Message
Результат void
        public void Send(Message msg)
        {
            Tracing.Information("[SmtpMessageDelivery.Send] sending mail to " + msg.To);
            if (!String.IsNullOrWhiteSpace(msg.Cc))
            {
                Tracing.Information("[SmtpMessageDelivery.Send] cc'ing mail to " + msg.Cc);
            }

            if (String.IsNullOrWhiteSpace(msg.From))
            {
                SmtpSection smtp = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;
                msg.From = smtp.From;
            }

            using (SmtpClient smtp = new SmtpClient())
            {
                smtp.Timeout = SmtpTimeout;
                try
                {
                    MailMessage mailMessage = new MailMessage(msg.From, msg.To, msg.Subject, msg.Body)
                    {
                        IsBodyHtml = SendAsHtml
                    };
                    if (!String.IsNullOrWhiteSpace(msg.Cc))
                    {
                        foreach (string email in msg.Cc.Split(',', ';'))
                        {
                            mailMessage.CC.Add(email);
                        }
                    }
                    smtp.Send(mailMessage);
                }
                catch (SmtpException e)
                {
                    Tracing.Error("[SmtpMessageDelivery.Send] SmtpException: " + e.Message);
                }
                catch (Exception e)
                {
                    Tracing.Error("[SmtpMessageDelivery.Send] Exception: " + e.Message);
                }
            }
        }
    }

Usage Example

 public IHttpActionResult TestMessageTemplate(Guid id)
 {
     if (id == default(Guid))
         return BadRequest("MessageTemplate id cannot be empty.");
     ClaimsPrincipal principal = HttpContext.Current.User as ClaimsPrincipal;
     if (principal == null)
         return NotFound();
     Claim emailClaim = principal.FindFirst(ClaimTypes.Email);
     if (emailClaim == null || string.IsNullOrEmpty(emailClaim.Value))
         return BadRequest("Cannot find email address.");
     string to = emailClaim.Value.Trim();
     IMessageTemplateService messageTemplateServce = IoC.GetService<IMessageTemplateService>();
     MessageTemplate template = messageTemplateServce.GetById(id);
     if (template == null)
         return BadRequest(string.Format("Cannot find email template {0}.", id));
     string subject = string.IsNullOrEmpty(template.Subject) ? null : Tokenize(template.Subject);
     string body = string.IsNullOrEmpty(template.Body) ? null : Tokenize(template.Body);
     var smtp = new SmtpMessageDelivery();
     var msg = new Message
     {
         To = to,
         Subject = "[Email Template Test] " + subject,
         Body = body
     };
     smtp.Send(msg);
     SessionMessageManager.SetMessage(MessageType.Success, MessageBehaviors.StatusBar, "Test email is sent.");
     return Ok();
 }
SmtpMessageDelivery