Beispiel #1
0
        public static EmailEntity GetTemplatedMessage(string templateName, EmailEntity message, StringDictionary namevalue)
        {
            string   emailAddressPlaceHolder = "#EmailAddress#";
            Template template = GetTemplate(templateName);

            if (message != null)
            {
                if (template != null)
                {
                    if (namevalue != null)
                    {
                        foreach (DictionaryEntry de in namevalue)
                        {
                            template.TemplateBody = template.TemplateBody.Replace(de.Key.ToString(), de.Value.ToString());
                        }
                        message.EmailBody = template.TemplateBody;
                        message.EmailBody = message.EmailBody.Replace(emailAddressPlaceHolder, message.EmailTo[0]);
                    }
                }

                AlternateView mailView = null;

                if (templateName.Equals("verify-account"))
                {
                    mailView = GetAlternateViewForVerfication(message);
                }
                else if (templateName.Equals("welcome"))
                {
                    mailView = GetAlternateViewForWelcome(message);
                }

                message.AlternateView = mailView;
            }
            return(message);
        }
Beispiel #2
0
        private static AlternateView GetAlternateViewForVerfication(EmailEntity message)
        {
            string path = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings.Get("TemplateFolderPath").ToString());

            string emptygifPath      = "images/empty.gif";
            string topjpgPath        = "images/top.jpg";
            string logogifPath       = "images/logo.gif";
            string cheersjpgPath     = "images/cheers.jpg";
            string welcomebtnjpgPath = "images/welcomebtm.jpg";
            string logobottomjpgPath = "images/logo_bottom.jpg";
            string bottomjpgPath     = "images/bottom.jpg";

            string emptygifContentId      = "emptygif";
            string topjpgContentId        = "topjpg";
            string logogifContentId       = "logogif";
            string cheersjpgContentId     = "cheersjpg";
            string welcomebtnjpgContentId = "welcomebtnjpg";
            string logobottomjpgContentId = "logobottomjpg";
            string bottomjpgContentId     = "bottomjpg";

            LinkedResource emptygifResource = new LinkedResource(path + emptygifPath);

            emptygifResource.ContentId = emptygifContentId;

            LinkedResource topjpgResource = new LinkedResource(path + topjpgPath);

            topjpgResource.ContentId = topjpgContentId;

            LinkedResource logogifResource = new LinkedResource(path + logogifPath);

            logogifResource.ContentId = logogifContentId;

            LinkedResource cheersjpgResource = new LinkedResource(path + cheersjpgPath);

            cheersjpgResource.ContentId = cheersjpgContentId;

            LinkedResource welcomebtnjpgResource = new LinkedResource(path + welcomebtnjpgPath);

            welcomebtnjpgResource.ContentId = welcomebtnjpgContentId;

            LinkedResource logobottomjpgResource = new LinkedResource(path + logobottomjpgPath);

            logobottomjpgResource.ContentId = logobottomjpgContentId;

            LinkedResource bottomjpgResource = new LinkedResource(path + bottomjpgPath);

            bottomjpgResource.ContentId = bottomjpgContentId;

            AlternateView mailView = AlternateView.CreateAlternateViewFromString(message.EmailBody, null, MediaTypeNames.Text.Html);

            mailView.LinkedResources.Add(emptygifResource);
            mailView.LinkedResources.Add(topjpgResource);
            mailView.LinkedResources.Add(logogifResource);
            mailView.LinkedResources.Add(cheersjpgResource);
            mailView.LinkedResources.Add(welcomebtnjpgResource);
            mailView.LinkedResources.Add(logobottomjpgResource);
            mailView.LinkedResources.Add(bottomjpgResource);
            return(mailView);
        }
Beispiel #3
0
        public static bool Send(EmailEntity em)
        {
            SmtpSetting site = GetSmtpSetting();
            if (site == null)
                return false;

            short connectionLimit = site.SmtpServerConnectionLimit;

            SmtpClient client = new SmtpClient();
            System.Net.NetworkCredential credential = new System.Net.NetworkCredential();
            credential.Password = site.SmtpServerPassword;
            credential.UserName = site.SmtpServerUserName;
            //client.Port = Convert.ToInt32(ConfigurationManager.AppSettings.Get("SmtpPortnumber"));
            client.Port = int.Parse(site.SmtpPortNumber);
            client.Host = site.SmtpServer;
            client.Credentials = credential;
            client.EnableSsl = true;

            try
            {
                MailMessage message = new MailMessage();
                message.From = new MailAddress(em.EmailFrom);
                foreach (string address in em.EmailTo)
                {
                    message.To.Add(new MailAddress(address));
                }
                message.Subject = em.EmailSubject;
                //
                if (em.AlternateView != null)
                {
                    message.AlternateViews.Add(em.AlternateView);
                }
                else
                {
                    message.Body = em.EmailBody;
                }
                //message.IsBodyHtml = em.IsHtml;
                message.IsBodyHtml = true;
                if ((em.EmailAttachement != null) && (!string.IsNullOrEmpty(em.AttachedfileName)))
                {
                    message.Attachments.Add(new Attachment(em.EmailAttachement, em.AttachedfileName));
                }
                // Set the body encoding
                try { message.BodyEncoding = Encoding.GetEncoding(site.EmailEncoding); }
                catch { message.BodyEncoding = Encoding.UTF8; }
                // Set the method that is called back when the send operation ends.
                //client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
                //string userState = "KoD Ticket Booking Email Notification";
                //client.SendAsync(message, userState);
                client.Send(message);

                //Console.WriteLine("Sending message... press c to cancel mail. Press any other key to exit.");
                //string answer = Console.ReadLine();
                //// If the user canceled the send, and mail hasn't been sent yet,
                //// then cancel the pending operation.
                //if (answer.StartsWith("c"))
                //{
                //    client.SendAsyncCancel();
                //}
                // Clean up.
                message.Dispose();
                Console.WriteLine("Goodbye.");

            }
            catch (System.Exception e)
            {
                Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(e.Message);
                throw e;
            }

            return true;
        }
Beispiel #4
0
        private static AlternateView GetAlternateViewForVerfication(EmailEntity message)
        {
            string path = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings.Get("TemplateFolderPath").ToString());

            string emptygifPath = "images/empty.gif";
            string topjpgPath = "images/top.jpg";
            string logogifPath = "images/logo.gif";
            string cheersjpgPath = "images/cheers.jpg";
            string welcomebtnjpgPath = "images/welcomebtm.jpg";
            string logobottomjpgPath = "images/logo_bottom.jpg";
            string bottomjpgPath = "images/bottom.jpg";

            string emptygifContentId = "emptygif";
            string topjpgContentId = "topjpg";
            string logogifContentId = "logogif";
            string cheersjpgContentId = "cheersjpg";
            string welcomebtnjpgContentId = "welcomebtnjpg";
            string logobottomjpgContentId = "logobottomjpg";
            string bottomjpgContentId = "bottomjpg";

            LinkedResource emptygifResource = new LinkedResource(path + emptygifPath);
            emptygifResource.ContentId = emptygifContentId;

            LinkedResource topjpgResource = new LinkedResource(path + topjpgPath);
            topjpgResource.ContentId = topjpgContentId;

            LinkedResource logogifResource = new LinkedResource(path + logogifPath);
            logogifResource.ContentId = logogifContentId;

            LinkedResource cheersjpgResource = new LinkedResource(path + cheersjpgPath);
            cheersjpgResource.ContentId = cheersjpgContentId;

            LinkedResource welcomebtnjpgResource = new LinkedResource(path + welcomebtnjpgPath);
            welcomebtnjpgResource.ContentId = welcomebtnjpgContentId;

            LinkedResource logobottomjpgResource = new LinkedResource(path + logobottomjpgPath);
            logobottomjpgResource.ContentId = logobottomjpgContentId;

            LinkedResource bottomjpgResource = new LinkedResource(path + bottomjpgPath);
            bottomjpgResource.ContentId = bottomjpgContentId;

            AlternateView mailView = AlternateView.CreateAlternateViewFromString(message.EmailBody, null, MediaTypeNames.Text.Html);
            mailView.LinkedResources.Add(emptygifResource);
            mailView.LinkedResources.Add(topjpgResource);
            mailView.LinkedResources.Add(logogifResource);
            mailView.LinkedResources.Add(cheersjpgResource);
            mailView.LinkedResources.Add(welcomebtnjpgResource);
            mailView.LinkedResources.Add(logobottomjpgResource);
            mailView.LinkedResources.Add(bottomjpgResource);
            return mailView;
        }
Beispiel #5
0
        private static AlternateView GetAlternateViewForWelcome(EmailEntity message)
        {
            string path = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings.Get("TemplateFolderPath").ToString());

            string emptygifPath = "images/empty.gif";
            string topjpgPath = "images/top.jpg";
            string logogifPath = "images/logo.gif";
            //string cheersjpgPath = "images/cheers.jpg";
            //string welcomebtnjpgPath = "images/welcomebtm.jpg";
            string logobottomjpgPath = "images/logo_bottom.jpg";
            string bottomjpgPath = "images/bottom.jpg";

            string emailjpgPath = "images/email.jpg";
            string welcomejpgPath = "images/welcome.jpg";
            string shadowjpgPath = "images/shadow.jpg";
            string gplusjpgPath = "images/gplus.jpg";
            string icofacebookjpgPath = "images/ico_facebook.jpg";
            string icotwitterjpgPath = "images/ico_twitter.jpg";


            string emptygifContentId = "emptygif";
            string topjpgContentId = "topjpg";
            string logogifContentId = "logogif";
            //string cheersjpgContentId = "cheersjpg";
            //string welcomebtnjpgContentId = "welcomebtnjpg";
            string logobottomjpgContentId = "logobottomjpg";
            string bottomjpgContentId = "bottomjpg";

            string emailjpgContentId = "emailjpg";
            string welcomejpgContentId = "welcomejpg";
            string shadowjpgContentId = "shadowjpg";
            string gplusjpgContentId = "gplusjpg";
            string icofacebookjpgContentId = "icofacebookjpg";
            string icotwitterjpgContentId = "icotwitterjpg";

            LinkedResource emptygifResource = new LinkedResource(path + emptygifPath);
            emptygifResource.ContentId = emptygifContentId;

            LinkedResource topjpgResource = new LinkedResource(path + topjpgPath);
            topjpgResource.ContentId = topjpgContentId;

            LinkedResource logogifResource = new LinkedResource(path + logogifPath);
            logogifResource.ContentId = logogifContentId;

            LinkedResource emailjpgResource = new LinkedResource(path + emailjpgPath);
            emailjpgResource.ContentId = emailjpgContentId;

            LinkedResource welcomejpgResource = new LinkedResource(path + welcomejpgPath);
            welcomejpgResource.ContentId = welcomejpgContentId;

            LinkedResource logobottomjpgResource = new LinkedResource(path + logobottomjpgPath);
            logobottomjpgResource.ContentId = logobottomjpgContentId;

            LinkedResource bottomjpgResource = new LinkedResource(path + bottomjpgPath);
            bottomjpgResource.ContentId = bottomjpgContentId;

            LinkedResource shadowjpgResource = new LinkedResource(path + shadowjpgPath);
            shadowjpgResource.ContentId = shadowjpgContentId;

            LinkedResource gplusjpgResource = new LinkedResource(path + gplusjpgPath);
            gplusjpgResource.ContentId = gplusjpgContentId;

            LinkedResource icofacebookjpgResource = new LinkedResource(path + icofacebookjpgPath);
            icofacebookjpgResource.ContentId = icofacebookjpgContentId;

            LinkedResource icotwitterjpgResource = new LinkedResource(path + icotwitterjpgPath);
            icotwitterjpgResource.ContentId = icotwitterjpgContentId;


            AlternateView mailView = AlternateView.CreateAlternateViewFromString(message.EmailBody, null, MediaTypeNames.Text.Html);
            mailView.LinkedResources.Add(emptygifResource);
            mailView.LinkedResources.Add(topjpgResource);
            mailView.LinkedResources.Add(logogifResource);
            mailView.LinkedResources.Add(emailjpgResource);
            mailView.LinkedResources.Add(welcomejpgResource);
            mailView.LinkedResources.Add(logobottomjpgResource);
            mailView.LinkedResources.Add(bottomjpgResource);

            mailView.LinkedResources.Add(shadowjpgResource);
            mailView.LinkedResources.Add(gplusjpgResource);
            mailView.LinkedResources.Add(icofacebookjpgResource);
            mailView.LinkedResources.Add(icotwitterjpgResource);

            return mailView;
        }
Beispiel #6
0
        public static EmailEntity GetTemplatedMessage(string templateName, EmailEntity message, StringDictionary namevalue)
        {
            string emailAddressPlaceHolder = "#EmailAddress#";
            Template template = GetTemplate(templateName);
            if (message != null)
            {
                if (template != null)
                {
                    if (namevalue != null)
                    {
                        foreach (DictionaryEntry de in namevalue)
                        {
                            template.TemplateBody = template.TemplateBody.Replace(de.Key.ToString(), de.Value.ToString());
                        }
                        message.EmailBody = template.TemplateBody;
                        message.EmailBody = message.EmailBody.Replace(emailAddressPlaceHolder, message.EmailTo[0]);
                    }
                }

                AlternateView mailView = null;

                if (templateName.Equals("verify-account"))
                {
                    mailView = GetAlternateViewForVerfication(message);
                }
                else if (templateName.Equals("welcome"))
                {
                    mailView = GetAlternateViewForWelcome(message);
                }

                message.AlternateView = mailView;
            }
            return message;
        }
Beispiel #7
0
        private static AlternateView GetAlternateViewForWelcome(EmailEntity message)
        {
            string path = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings.Get("TemplateFolderPath").ToString());

            string emptygifPath = "images/empty.gif";
            string topjpgPath   = "images/top.jpg";
            string logogifPath  = "images/logo.gif";
            //string cheersjpgPath = "images/cheers.jpg";
            //string welcomebtnjpgPath = "images/welcomebtm.jpg";
            string logobottomjpgPath = "images/logo_bottom.jpg";
            string bottomjpgPath     = "images/bottom.jpg";

            string emailjpgPath       = "images/email.jpg";
            string welcomejpgPath     = "images/welcome.jpg";
            string shadowjpgPath      = "images/shadow.jpg";
            string gplusjpgPath       = "images/gplus.jpg";
            string icofacebookjpgPath = "images/ico_facebook.jpg";
            string icotwitterjpgPath  = "images/ico_twitter.jpg";


            string emptygifContentId = "emptygif";
            string topjpgContentId   = "topjpg";
            string logogifContentId  = "logogif";
            //string cheersjpgContentId = "cheersjpg";
            //string welcomebtnjpgContentId = "welcomebtnjpg";
            string logobottomjpgContentId = "logobottomjpg";
            string bottomjpgContentId     = "bottomjpg";

            string emailjpgContentId       = "emailjpg";
            string welcomejpgContentId     = "welcomejpg";
            string shadowjpgContentId      = "shadowjpg";
            string gplusjpgContentId       = "gplusjpg";
            string icofacebookjpgContentId = "icofacebookjpg";
            string icotwitterjpgContentId  = "icotwitterjpg";

            LinkedResource emptygifResource = new LinkedResource(path + emptygifPath);

            emptygifResource.ContentId = emptygifContentId;

            LinkedResource topjpgResource = new LinkedResource(path + topjpgPath);

            topjpgResource.ContentId = topjpgContentId;

            LinkedResource logogifResource = new LinkedResource(path + logogifPath);

            logogifResource.ContentId = logogifContentId;

            LinkedResource emailjpgResource = new LinkedResource(path + emailjpgPath);

            emailjpgResource.ContentId = emailjpgContentId;

            LinkedResource welcomejpgResource = new LinkedResource(path + welcomejpgPath);

            welcomejpgResource.ContentId = welcomejpgContentId;

            LinkedResource logobottomjpgResource = new LinkedResource(path + logobottomjpgPath);

            logobottomjpgResource.ContentId = logobottomjpgContentId;

            LinkedResource bottomjpgResource = new LinkedResource(path + bottomjpgPath);

            bottomjpgResource.ContentId = bottomjpgContentId;

            LinkedResource shadowjpgResource = new LinkedResource(path + shadowjpgPath);

            shadowjpgResource.ContentId = shadowjpgContentId;

            LinkedResource gplusjpgResource = new LinkedResource(path + gplusjpgPath);

            gplusjpgResource.ContentId = gplusjpgContentId;

            LinkedResource icofacebookjpgResource = new LinkedResource(path + icofacebookjpgPath);

            icofacebookjpgResource.ContentId = icofacebookjpgContentId;

            LinkedResource icotwitterjpgResource = new LinkedResource(path + icotwitterjpgPath);

            icotwitterjpgResource.ContentId = icotwitterjpgContentId;


            AlternateView mailView = AlternateView.CreateAlternateViewFromString(message.EmailBody, null, MediaTypeNames.Text.Html);

            mailView.LinkedResources.Add(emptygifResource);
            mailView.LinkedResources.Add(topjpgResource);
            mailView.LinkedResources.Add(logogifResource);
            mailView.LinkedResources.Add(emailjpgResource);
            mailView.LinkedResources.Add(welcomejpgResource);
            mailView.LinkedResources.Add(logobottomjpgResource);
            mailView.LinkedResources.Add(bottomjpgResource);

            mailView.LinkedResources.Add(shadowjpgResource);
            mailView.LinkedResources.Add(gplusjpgResource);
            mailView.LinkedResources.Add(icofacebookjpgResource);
            mailView.LinkedResources.Add(icotwitterjpgResource);

            return(mailView);
        }
Beispiel #8
0
        public static bool Send(EmailEntity em)
        {
            SmtpSetting site = GetSmtpSetting();

            if (site == null)
            {
                return(false);
            }

            short connectionLimit = site.SmtpServerConnectionLimit;

            SmtpClient client = new SmtpClient();

            System.Net.NetworkCredential credential = new System.Net.NetworkCredential();
            credential.Password = site.SmtpServerPassword;
            credential.UserName = site.SmtpServerUserName;
            //client.Port = Convert.ToInt32(ConfigurationManager.AppSettings.Get("SmtpPortnumber"));
            client.Port        = int.Parse(site.SmtpPortNumber);
            client.Host        = site.SmtpServer;
            client.Credentials = credential;
            client.EnableSsl   = true;

            try
            {
                MailMessage message = new MailMessage();
                message.From = new MailAddress(em.EmailFrom);
                foreach (string address in em.EmailTo)
                {
                    message.To.Add(new MailAddress(address));
                }
                message.Subject = em.EmailSubject;
                //
                if (em.AlternateView != null)
                {
                    message.AlternateViews.Add(em.AlternateView);
                }
                else
                {
                    message.Body = em.EmailBody;
                }
                //message.IsBodyHtml = em.IsHtml;
                message.IsBodyHtml = true;
                if ((em.EmailAttachement != null) && (!string.IsNullOrEmpty(em.AttachedfileName)))
                {
                    message.Attachments.Add(new Attachment(em.EmailAttachement, em.AttachedfileName));
                }
                // Set the body encoding
                try { message.BodyEncoding = Encoding.GetEncoding(site.EmailEncoding); }
                catch { message.BodyEncoding = Encoding.UTF8; }
                // Set the method that is called back when the send operation ends.
                //client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
                //string userState = "KoD Ticket Booking Email Notification";
                //client.SendAsync(message, userState);
                client.Send(message);

                //Console.WriteLine("Sending message... press c to cancel mail. Press any other key to exit.");
                //string answer = Console.ReadLine();
                //// If the user canceled the send, and mail hasn't been sent yet,
                //// then cancel the pending operation.
                //if (answer.StartsWith("c"))
                //{
                //    client.SendAsyncCancel();
                //}
                // Clean up.
                message.Dispose();
                Console.WriteLine("Goodbye.");
            }
            catch (System.Exception e)
            {
                Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(e.Message);
                throw e;
            }

            return(true);
        }