public void SendEmailWithTemplate(MailMessage mailMessage, Dictionary <string, string> mergeVariables, string templateName, string[] tags = null)
        {
            var message = new MailChimp.Types.Mandrill.Messages.Message
            {
                To        = mailMessage.To.Select(o => new MailChimp.Types.Mandrill.Messages.Recipient(o.Address, o.DisplayName)).ToArray(),
                FromEmail = mailMessage.From.Address,
                FromName  = String.IsNullOrEmpty(mailMessage.From.DisplayName) ? mailMessage.From.DisplayName: "DefaultName",
                Subject   = mailMessage.Subject,
                Html      = null,
                Text      = null
            };

            if (mailMessage.ReplyToList.Any())
            {
                message.Headers = new MCDict <MailChimp.Types.Mandrill.Messages.Header> {
                    { "Reply-To", mailMessage.ReplyToList.First().Address }
                }
            }
            ;

            var k = new MailChimp.Types.Mandrill.NameContentList <string>();

            foreach (var mergeVariable in mergeVariables)
            {
                k.Add(mergeVariable.Key, mergeVariable.Value);
            }

            message.GlobalMergeVars = new Opt <MailChimp.Types.Mandrill.NameContentList <string> >(k);

            _mandrillApi.SendTemplate(templateName, k, message);
        }
Ejemplo n.º 2
0
        public void NotifySuperAdmin(string email,string subject, string body, string templateName)
        {
            var toList = ConfigurationManager.AppSettings["SuperAdminToEmails"].Split(';');
            var recipientCount = toList.Count();
            var count = 0;

            MN.Messages.Recipient[] recipients = new MN.Messages.Recipient[recipientCount];
            foreach (var to in toList)
            {
                recipients[count] = new MN.Messages.Recipient(to, to);
                count++;
            }
            var m = new MandrillApi(key);
            //Mail settings for mandrill
            var message = new MN.Messages.Message();
            message.Subject = subject;
            message.FromEmail = ConfigurationManager.AppSettings["SupportEmailID"];
            message.FromName = "LockYourStay";
            message.To = recipients;

            //mergevars for dynamic content in mandrill template
            var globalMergeVars = new Mandrill.Merges();
            globalMergeVars.Add("SUBJECT", message.Subject);
            globalMergeVars.Add("BODY", body);

            message.GlobalMergeVars = globalMergeVars; // common information for all receipient

            //dynamic template content
            var templateContent = new List<Mandrill.NameContentPair<string>>();
            templateContent.Add(new Mandrill.NameContentPair<string>("SUBJECT", message.Subject));
            templateContent.Add(new Mandrill.NameContentPair<string>("BODY", body));

            //Send mail
            m.SendTemplate(templateName, templateContent, message);
        }
Ejemplo n.º 3
0
        public void NotifyUser(string email,string name,string subject,string body,string templateName)
        {
            var m = new MandrillApi(key);
            //Mail settings for mandrill
            var message = new MN.Messages.Message();
            message.Subject = subject;
            message.FromEmail = ConfigurationManager.AppSettings["SupportEmailID"];
            message.FromName = "LockYourStay";
            message.To = new[] { new MN.Messages.Recipient(email, email) };

            //mergevars for dynamic content in mandrill template
            var globalMergeVars = new Mandrill.Merges();
            globalMergeVars.Add("SUBJECT", message.Subject);
            globalMergeVars.Add("NAME", name);
            globalMergeVars.Add("BODY", body);

            message.GlobalMergeVars = globalMergeVars; // common information for all receipient

            //dynamic template content
            var templateContent = new List<Mandrill.NameContentPair<string>>();
            templateContent.Add(new Mandrill.NameContentPair<string>("SUBJECT", message.Subject));
            templateContent.Add(new Mandrill.NameContentPair<string>("NAME", name));
            templateContent.Add(new Mandrill.NameContentPair<string>("BODY", body));

            //Send mail
            m.SendTemplate(templateName, templateContent, message);
        }