Esempio n. 1
0
        //http://aboutcode.net/postal/outside-aspnet.html
        //http://aboutcode.net/postal/multi-part.html
        //http://aboutcode.net/postal/
        public void SendPostalEmail(EmailAccount emailAccount, BasePostalMail mail, 
            IEnumerable<MailAttachment> attachments = null)
        {
            // Get the path to the directory containing views
            var viewsPath = CommonHelper.PostalViewPath;
           viewsPath = Path.GetFullPath(viewsPath);
            dynamic _mail = mail;
           
            var engines = new ViewEngineCollection();
            engines.Add(new FileSystemRazorViewEngine(viewsPath));
            using (var smtpClient = new SmtpClient())
            {
                smtpClient.UseDefaultCredentials = emailAccount.UseDefaultCredentials;
                smtpClient.Host = emailAccount.Host;
                smtpClient.Port = emailAccount.Port;
                smtpClient.EnableSsl = emailAccount.EnableSsl;
                if (emailAccount.UseDefaultCredentials)
                    smtpClient.Credentials = CredentialCache.DefaultNetworkCredentials;
                else
                    smtpClient.Credentials = new NetworkCredential(emailAccount.Username, emailAccount.Password);

                var service = new EmailService(engines, () => smtpClient);
                if (attachments != null)
                {
                    if (attachments.Count() > 0)
                    {
                        foreach (MailAttachment s in attachments)
                        {
                            mail.Attach(new Attachment(s.FileStream, s.Name, s.ContentType.MediaType));
                        }
                    }
                }
              


                service.Send(mail);


            }
          
          
          
        }
Esempio n. 2
0
       public MailMessage GetMailMessage(BasePostalMail mail)
        {
            dynamic _mail = mail;
            var emailService = new EmailService();
            var message = emailService.CreateMailMessage(mail);
           
            return message;

        }