Ejemplo n.º 1
0
        /// <summary>
        /// Send the mail to the list of users based on the defined template
        /// </summary>
        /// <param name="emailTolist"></param>
        /// <param name="subject"></param>
        /// <param name="message"></param>
        /// <param name="templateFileName"></param>
        /// <param name="emailCcList"></param>
        /// <param name="emailBccList"></param>
        /// <returns></returns>
        public void Send(List <string> emailTolist, string subject, List <string> changeObject, Dictionary <string, string> changeValue, string templateFileName, List <string> emailCcList = null, List <string> emailBccList = null)
        {
            SetSupporInfo(changeValue);
            GetEmailSetting();

            // Example asynchronous request
            PostmarkMessage message = new PostmarkMessage()
            {
                From = senderEmail,
                Cc   = string.IsNullOrEmpty(_appSettings.EmailSettings.CCEmail) ? null : _appSettings.EmailSettings.CCEmail
            };

            foreach (var email in emailTolist)
            {
                message.To = email;
            }

            if (emailCcList != null && emailCcList.Count > 0)
            {
                foreach (var emailCc in emailTolist)
                {
                    message.Cc = emailCc;
                }
            }

            if (emailBccList != null && emailBccList.Count > 0)
            {
                foreach (var emailBcc in emailBccList)
                {
                    message.Cc = emailBcc;
                }
            }

            message.Subject = subject;


            string emailBody = BodyTemplate.CreateMailBody(changeObject, changeValue, templateFileName, senderName, NotificationType.Email);

            message.HtmlBody = emailBody;

            //File Attachment for Images in Mail
            string        filePath = Directory.GetCurrentDirectory() + "\\wwwroot\\TemplateImages\\";
            List <string> files    = Directory.GetFiles(filePath).ToList();

            foreach (string file in files)
            {
                var imageContent = File.ReadAllBytes(file);
                message.AddAttachment(imageContent, file.Replace(filePath, "").ToLower(), "image/png", "cid:" + file.Replace(filePath, "").ToLower());
            }

            var client     = new PostmarkClient(postMarkKey);
            var sendResult = client.SendMessageAsync(message);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Send the mail to the list of users based on the defined template
        /// </summary>
        /// <param name="emailTolist"></param>
        /// <param name="subject"></param>
        /// <param name="message"></param>
        /// <param name="templateFileName"></param>
        /// <param name="emailCcList"></param>
        /// <param name="emailBccList"></param>
        /// <returns></returns>
        public void Send(List <string> emailTolist, string subject, string message, string templateFileName, List <string> emailCcList = null, List <string> emailBccList = null, string name = "")
        {
            GetEmailSetting();

            // Example asynchronous request
            PostmarkMessage postMarkMessage = new PostmarkMessage()
            {
                From = senderEmail,
            };

            foreach (var email in emailTolist)
            {
                postMarkMessage.To = email;
            }

            if (emailCcList != null && emailCcList.Count > 0)
            {
                foreach (var emailCc in emailTolist)
                {
                    postMarkMessage.Cc = emailCc;
                }
            }

            if (emailBccList != null && emailBccList.Count > 0)
            {
                foreach (var emailBcc in emailBccList)
                {
                    postMarkMessage.Cc = emailBcc;
                }
            }

            postMarkMessage.Subject = subject;


            string emailBody = BodyTemplate.CreateMailBody(message, templateFileName, senderName, NotificationType.Email, name);

            postMarkMessage.HtmlBody = emailBody;


            //var imageContent = File.ReadAllBytes("test.jpg");
            //message.AddAttachment(imageContent, "test.jpg", "image/jpg", "cid:embed_name.jpg");

            var client     = new PostmarkClient(postMarkKey);
            var sendResult = client.SendMessageAsync(postMarkMessage);
        }