Esempio n. 1
0
 //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);
     }
 }
Esempio n. 2
0
 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();
     }
 }
Esempio n. 3
0
        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();
            }
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
            }
        }
Esempio n. 7
0
        //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);
        }
Esempio n. 8
0
 //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);
     }
 }
Esempio n. 9
0
        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);
                    }
                }
            }
        }
Esempio n. 10
0
 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);
 }
Esempio n. 11
0
 public void LoadBase(MailBase mail)
 {
     this.MailMessage.SyncButNoIdTo(mail);
     this.MailMessage.ID = mail.ID;
 }