MWS.Core.EmailQueueManager.SendEmail C# (CSharp) Method

SendEmail() public method

create SmtpClient, create mail message, and send message. Catches exceptions and puts them in QueueManager.ExceptionStack.
public SendEmail ( Email e, EmailServerConfig cfg ) : bool
e Machete.Domain.Email
cfg EmailServerConfig
return bool
        public bool SendEmail(Email e, EmailServerConfig cfg)
        {
            try
            {
                e.emailFrom = cfg.OutgoingAccount;
                var client = new SmtpClient(cfg.HostName, cfg.Port)
                {
                    Credentials = new NetworkCredential(cfg.OutgoingAccount, cfg.OutgoingPassword),
                    EnableSsl = cfg.EnableSSL
                };
                var msg = new MailMessage(e.emailFrom, e.emailTo);
                if (e.attachment != null)
                {
                    var a = Attachment.CreateAttachmentFromString(e.attachment, e.attachmentContentType);
                    a.Name = "Order.html";
                    msg.Attachments.Add(a);
                }
                msg.Subject = e.subject;
                msg.Body = e.body;
                client.Send(msg);

                e.statusID = Email.iSent; // record sent
                sentStack.Push(e);
            }
            catch (Exception ex)
            {
                //  don't log the repeating message
                if (exceptionStack.Count() == 0 ||
                    exceptionStack.Peek().Message != ex.Message)
                {
                    exceptionStack.Push(ex);
                }
                e.statusID = Email.iTransmitError;
            }
            finally
            {
                e.lastAttempt = DateTime.Now;
                e.transmitAttempts += 1;
            }
            return true;
        }