//Forward mail base on exist mail private void ForwardTo(object o) { if (o is object[]) { var parameters = o as object[]; if (null == parameters) { return; } var type = parameters[0] as Type; var extra = parameters[1] as MailMsgBase; MailBase mail = null; try { mail = new MailBase() { BodyHtml = extra.BodyHtmlText, BodyText = extra.BodyText, Subject = "FW: " + extra.Subject }; } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } var msg = new NavigationMessage(type, mail, Tokens.NavEdit); Messenger.Default.Send(msg, Tokens.Main); Messenger.Default.Send(msg, Tokens.Draft); } }
public void Send(MailBase mail) { if (mail is IEmailBase email) { foreach (var recipient in mail.Recipients) { var sentMailsModel = new SentMails { Body = email.Body, Subject = email.Subject, IsSent = false, CreatedUtcDate = DateTime.UtcNow, FromEmail = email.FromEmail ?? string.Empty, FromName = email.FromName ?? string.Empty, ToEmail = recipient.Email, ToName = recipient.Name, }; _sentMailsService.Insert(sentMailsModel); } } else { throw new NotImplementedException(); } }
public async Task SendAsync(MailBase mail) { var email = mail as IEmailBase; if (email != null) { foreach (var recipient in mail.Recipients) { var sentMailsModel = new SentMails { Body = email.Body, Subject = email.Subject, IsSent = false, CreatedUtcDate = DateTime.UtcNow, FromEmail = email.FromEmail ?? string.Empty, FromName = email.FromName ?? string.Empty, ToEmail = recipient.Email, ToName = recipient.Name, }; await _sentMailsService.InsertAsync(sentMailsModel); } } else { throw new NotImplementedException(); } }
public void SendMailUsingTemplate(MailBase model) { // Get the path to the directory containing views //var viewsPath = Path.GetFullPath(@"..\Debug\MailTemplates"); //var engines = new ViewEngineCollection(); //var path = new FileSystemRazorViewEngine(viewsPath); //engines.Add((IViewEngine)path); //var service = new EmailService(engines); //service.Send(model); var viewsPath = Path.GetFullPath(@"..\..\Views"); var engines = new ViewEngineCollection(); engines.Add(new FileSystemRazorViewEngine(viewsPath)); var service = new EmailService(engines); dynamic email = new Email("Test"); email.Message = "Hello, non-asp.net world!"; service.Send(email); }
public void Test() { var mailer = new Mailer(); var model = new MailBase() { Subject = "Test", Template = Consts.MailTemplates.Example }; model.Recipients = new List <MailAddress>(); model.Recipients.Add(new MailAddress("*****@*****.**")); mailer.SendMailUsingTemplate(model); }
public void SendMailByTypeAndDay(MailBase mail, string email, DateTime date, NotificationTypeEnum mailTemplateTypeEnum) { var query = new EmailLogQuery { StartCreateDate = new DateTime(date.Year, date.Month, date.Day), TypeId = GetEmailTemplatePublishedContentId(mailTemplateTypeEnum), ToEmail = email }; _sentMailsService.GetAllByFilter(query, out var totalCount); if (totalCount == 0) { Send(mail); } }
//Call navigate to New draft page by NavigationMessage private void NavigateNewDraft(object o) { Type type = o as Type; if (null == type) { return; } var newMail = new MailBase { ID = Guid.NewGuid().ToString("N"), BodyHtml = "Hi" }; var msg = new NavigationMessage(type, newMail, Tokens.NavEdit); Messenger.Default.Send(msg, Tokens.Main); Messenger.Default.Send(msg, Tokens.Draft); }
//Reply mail base on exist mail //use NavigationMessage private void ReplyMailFrom(object o) { if (o is object[]) { var parameters = o as object[]; if (null == parameters) { return; } var type = parameters[0] as Type; var extra = parameters[1] as MailMsgBase; var mail = new MailBase() { BodyHtml = extra.BodyHtmlText, BodyText = extra.BodyText, Subject = "RE: " + extra.Subject, ToAddresses = extra.From[0].Address }; var msg = new NavigationMessage(type, mail, Tokens.NavEdit); Messenger.Default.Send(msg, Tokens.Main); Messenger.Default.Send(msg, Tokens.Draft); } }
public void SaveDraftChanges(MailBase mail) { string mailId = mail.ID; if (string.IsNullOrEmpty(mailId)) { mail.ID = CreateId(); this.AddDraft(mail); } else { var existMail = DraftList.FirstOrDefault(item => { return(item.ID == mailId); }); if (existMail == null) { this.AddDraft(mail); } else { System.Diagnostics.Debug.WriteLine("Save changes of " + mail.ID); if (string.IsNullOrEmpty(mail.Subject) && string.IsNullOrEmpty(mail.BodyHtml) && string.IsNullOrEmpty(mail.BodyText)) { RemoveDraft(mail.ID); } else { existMail.SyncButNoIdTo(mail); SerializeAssistant.Serialize(draftBinPath, DraftList); } } } }
public void AddDraft(MailBase mail) { if (null == mail) { return; } if (DraftList.Contains(mail)) { return; } if (string.IsNullOrEmpty(mail.Subject) && string.IsNullOrEmpty(mail.BodyHtml) && string.IsNullOrEmpty(mail.BodyText)) { return; } if (string.IsNullOrEmpty(mail.ID)) { mail.ID = CreateId(); } System.Diagnostics.Debug.WriteLine("Add " + mail.ID); DraftList.Add(mail); SerializeAssistant.Serialize(draftBinPath, DraftList); }
public void LoadBase(MailBase mail) { this.MailMessage.SyncButNoIdTo(mail); this.MailMessage.ID = mail.ID; }