Exemplo n.º 1
0
        public static void SendMail(EmailTemplate emailTemplate)
        {
            //person must manually copy file to file folder
            //mail should be in html format
            //all mails in folder will be copied over to bin folder
            //for items that are to be replaced place them in the form <%KeyString %> //

            var emailFilePath = String.Format(@"\Email\{0}.html", emailTemplate.FileName);
            //var pathDirectory = System.AppDomain.CurrentDomain.BaseDirectory;
            //var path = (new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath;

            var path2 = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            var fullFilePath = path2 + emailFilePath;
            var fullFilePath2 = new Uri(fullFilePath).LocalPath;

            var emailTemplateFile = System.IO.File.ReadAllText(fullFilePath2);

            var emailStringBuilder = new StringBuilder(emailTemplateFile);

            foreach (var item in emailTemplate.dictionaryReplacements)
            {
                emailStringBuilder = emailStringBuilder.Replace(item.Key, item.Value);
            }

            Mailer.SendEmail(new Services.Models.EmailTemplate()
            {

                FromEmailAddress = emailTemplate.FromEmailAddress,
                FromName = emailTemplate.FromName,
                Subject = emailTemplate.Subject,
                ToEmailAddress = emailTemplate.ToEmailAddress,
                ToName = emailTemplate.ToName,
                Body = emailStringBuilder.ToString()
            });
        }
 public void SendMail()
 {
     EmailTemplate testTemplate = new EmailTemplate()
     {
         FileName = "ApplicationException",
         FromEmailAddress = "*****@*****.**",
         FromName = "Christopher Walton",
         Subject = "Application Exception",
         ToEmailAddress = "*****@*****.**",
         ToName = "*****@*****.**"
     };
     MailHelper.SendMail(testTemplate);
 }
Exemplo n.º 3
0
        private static void Main(string[] args)
        {
            EmailTemplate testTemplate = new EmailTemplate(){
                FileName = "ApplicationException",
                FromEmailAddress="*****@*****.**",
                FromName="Christopher Walton",
                Subject = "Application Exception",
                ToEmailAddress = "*****@*****.**",
                ToName = "*****@*****.**"
             };

            testTemplate.dictionaryReplacements.Add("<%ApplicationName%>", "PPEManager");

            MailHelper.SendMail(testTemplate);
        }
        private void SendInvalidDataUserEmail(string personName)
        {
            EmailTemplate testTemplate = new EmailTemplate()
            {
                FileName = "InvalidPersonData",
                FromEmailAddress = "*****@*****.**",
                FromName = "Christopher Walton",
                Subject = "Invalid Person Data",
                ToEmailAddress = "*****@*****.**",
                ToName = "*****@*****.**",
                dictionaryReplacements = new Dictionary<string, string>()
            };

            testTemplate.dictionaryReplacements.Add("<%ApplicationName%>", "PPEManager");
            testTemplate.dictionaryReplacements.Add("<%PersonName%>", personName);

            MailHelper.SendMail(testTemplate);
        }