/// <summary>
        /// create SmtpClient, create mail message, and send message. Catches exceptions and puts them in QueueManager.ExceptionStack.
        /// </summary>
        /// <param name="e"></param>
        /// <param name="cfg"></param>
        /// <returns></returns>
        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;
        }
 /// <summary>
 /// Get emails from EmailService and calle SendMail to send emails
 /// </summary>
 /// <param name="cfg"></param>
 public void ProcessQueue(EmailServerConfig cfg)
 {
     exceptionStack = new Stack<Exception>();
     sentStack = new Stack<Email>();
     //
     var emaillist = serv.GetEmailsToSend();
     foreach (var e in emaillist)
     {
         SendEmail(e, cfg);
     }
     db.Commit();
 }