private static long StoreMailHistory(System.Net.Mail.MailMessage mailMessage, string type, bool sendSuccess, string errorMessage)
        {
            var mail = new MailHistory();
            mail.CreatedOn = mail.LastSendDate = DateTime.Now;
            mail.SenderName = !string.IsNullOrEmpty(mailMessage.Sender.DisplayName) ? mailMessage.Sender.DisplayName : mailMessage.Sender.Address;
            mail.SenderAddress = mailMessage.Sender.Address;
            mail.Subject = mailMessage.Subject;
            mail.Success = sendSuccess;
            mail.Recipients = mailMessage.To.ToSeparatedString(";");
            mail.BccRecipients = mailMessage.Bcc.ToSeparatedString(";");
            mail.ErrorMessage = sendSuccess ? "" : errorMessage;
            mail.Body = mailMessage.Body;
            mail.Type = type;

            mail.Attachments = mailMessage.Attachments.Select(a => a.ContentDisposition.FileName).ToSeparatedString(";");

            var dataContext = GetDataContext();
            dataContext.MailHistories.InsertOnSubmit(mail);
            dataContext.SubmitChanges();

            return mail.Id;
        }
 partial void UpdateMailHistory(MailHistory instance);
 partial void DeleteMailHistory(MailHistory instance);
 partial void InsertMailHistory(MailHistory instance);