/// <summary> /// Convert QueuedEmail Object into QueuedEmail Entity /// </summary> ///<param name="model">QueuedEmail</param> ///<param name="QueuedEmailEntity">DataAccess.QueuedEmail</param> ///<returns>DataAccess.QueuedEmail</returns> public static DataAccess.QueuedEmail ToEntity(this QueuedEmailViewModel model, DataAccess.QueuedEmail entity ) { if (entity.Id == 0) { } else { entity.UpdatedUserId = model.SessionUserId; entity.UpdatedTimestamp = DateTime.Now; } entity.Id = model.Id; entity.Priority = model.Priority; entity.From = model.From; entity.FromName = model.FromName; entity.To = model.To; entity.ToName = model.ToName; entity.ReplyTo = model.ReplyTo; entity.ReplyToName = model.ReplyToName; entity.CC = model.CC; entity.BCC = model.BCC; entity.Subject = model.Subject; entity.Body = model.Body; entity.AttachmentFilePath = model.AttachmentFilePath; entity.AttachmentFileName = model.AttachmentFileName; entity.DontSendBeforeDate = model.DontSendBeforeDate; entity.SentTries = model.SentTries; entity.SentOn = model.SentOn; entity.EmailAccountId = model.EmailAccountId; return(entity); }
/// <summary> /// Convert QueuedEmail Entity into QueuedEmail Object /// </summary> ///<param name="model">QueuedEmailViewModel</param> ///<param name="QueuedEmailEntity">DataAccess.QueuedEmail</param> ///<returns>QueuedEmailViewModel</returns> public static QueuedEmailViewModel ToViewModel( this DataAccess.QueuedEmail entity, QueuedEmailViewModel model) { model.Id = entity.Id; model.Priority = entity.Priority; model.From = entity.From; model.FromName = entity.FromName; model.To = entity.To; model.ToName = entity.ToName; model.ReplyTo = entity.ReplyTo; model.ReplyToName = entity.ReplyToName; model.CC = entity.CC; model.BCC = entity.BCC; model.Subject = entity.Subject; model.Body = entity.Body; model.AttachmentFilePath = entity.AttachmentFilePath; model.AttachmentFileName = entity.AttachmentFileName; model.DontSendBeforeDate = entity.DontSendBeforeDate; model.SentTries = entity.SentTries; model.SentOn = entity.SentOn; model.SentOnString = entity.SentOn.ToCustomLongDateTime(); model.EmailAccountId = entity.EmailAccountId; return(model); }
public static DataAccess.QueuedEmail ToEntity(this DataAccess.QueuedEmail entity ) { return(new DataAccess.QueuedEmail { Priority = entity.Priority, From = entity.From, FromName = entity.FromName, To = entity.To, ToName = entity.ToName, ReplyTo = entity.ReplyTo, ReplyToName = entity.ReplyToName, CC = entity.CC, BCC = entity.BCC, Subject = entity.Subject, Body = entity.Body, AttachmentFilePath = entity.AttachmentFilePath, AttachmentFileName = entity.AttachmentFileName, DontSendBeforeDate = entity.DontSendBeforeDate, SentTries = entity.SentTries, EmailAccountId = entity.EmailAccountId, }); }
public Dictionary <bool, string> SendEmail(DataAccess.QueuedEmail emailRecord) { Dictionary <bool, string> dictionary = new Dictionary <bool, string>(); SmtpClient SmtpServer = new SmtpClient(); var credential = new NetworkCredential { UserName = emailRecord.EmailAccount.Username, Password = emailRecord.EmailAccount.Password, }; try { SmtpServer.Credentials = credential; SmtpServer.Host = string.Format("{0}", emailRecord.EmailAccount.Host); MailMessage mail = new MailMessage(); var portNumber = emailRecord.EmailAccount.Port; if (portNumber != 0) { SmtpServer.Port = portNumber; SmtpServer.EnableSsl = true; } mail.From = new MailAddress(emailRecord.From); mail.To.Add(emailRecord.To); mail.Subject = emailRecord.Subject; mail.IsBodyHtml = true; #region Embedded Image AlternateView avHtml = AlternateView.CreateAlternateViewFromString(emailRecord.Body, null, MediaTypeNames.Text.Html); // Create a LinkedResource object for each embedded image var imagePath = GetImage(); LinkedResource pic1 = new LinkedResource(imagePath, MediaTypeNames.Image.Jpeg) { ContentId = "Logo" }; avHtml.LinkedResources.Add(pic1); mail.AlternateViews.Add(avHtml); #endregion if (emailRecord.FileByte != null && emailRecord.FileByte.Length > 0) { //GenerateEmailAttachment(emailRecord.FileByte, mail); } if (!SmtpServer.EnableSsl) { SendToLocalFolder(SmtpServer); } SmtpServer.Send(mail); dictionary.Add(true, string.Empty); return(dictionary); } catch (Exception exception) { dictionary.Add(false, exception.ToString()); return(dictionary); } }