Exemple #1
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);
        }
        public string SendEmail(SendEmail emailMessage)
        {
            using (var session = DocumentStore.GetStore().OpenSession(DocumentStore.ConfigurationDatabaseName()))
            {
                var mandrillConfig = session.Load<MailgunConfiguration>("MandrillConfig");
                if (mandrillConfig == null)
                {
                    throw new NotImplementedException();
                }

                var api = new MandrillApi(mandrillConfig.ApiKey);
                var message = new MailChimp.Types.Mandrill.Messages.Message();

                message.Html = emailMessage.BaseRequest.BodyHtml;
                message.Text = emailMessage.BaseRequest.BodyText;
                message.To = new[]{new MailChimp.Types.Mandrill.Messages.Recipient(emailMessage.BaseRequest.ToAddress, emailMessage.BaseRequest.ToAddress), }; //new List<EmailAddress>() {new EmailAddress(emailMessage.BaseRequest.ToAddress)};
                message.Subject = emailMessage.BaseRequest.Subject;
                message.FromEmail = emailMessage.BaseRequest.FromAddress;
                message.FromName = emailMessage.BaseRequest.FromDisplayName;
                var result = api.Send(message);
                if (result == null || result.Count == 0)
                    throw new Exception("Email should be getting something back....");
                if (result[0].Status == MailChimp.Types.Mandrill.Messages.Status.Invalid || result[0].Status == MailChimp.Types.Mandrill.Messages.Status.Bounced || result[0].Status == MailChimp.Types.Mandrill.Messages.Status.Rejected || result[0].Status == MailChimp.Types.Mandrill.Messages.Status.SoftBounced)
                    throw new Exception("Some exception because email failed");
                return result[0].ID;
            }
        }
Exemple #3
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);
        }
        public async Task SendEmailWithTemplateAsync(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);

            await Task.Run(() => _mandrillApi.SendTemplate(templateName, k, message));
        }
    }
        public string SendEmail(SendEmail emailMessage)
        {
            using (var session = DocumentStore.GetStore().OpenSession(DocumentStore.ConfigurationDatabaseName()))
            {
                var mandrillConfig = session.Load <MailgunConfiguration>("MandrillConfig");
                if (mandrillConfig == null)
                {
                    throw new NotImplementedException();
                }

                var api     = new MandrillApi(mandrillConfig.ApiKey);
                var message = new MailChimp.Types.Mandrill.Messages.Message();

                message.Html      = emailMessage.BaseRequest.BodyHtml;
                message.Text      = emailMessage.BaseRequest.BodyText;
                message.To        = new[] { new MailChimp.Types.Mandrill.Messages.Recipient(emailMessage.BaseRequest.ToAddress, emailMessage.BaseRequest.ToAddress), }; //new List<EmailAddress>() {new EmailAddress(emailMessage.BaseRequest.ToAddress)};
                message.Subject   = emailMessage.BaseRequest.Subject;
                message.FromEmail = emailMessage.BaseRequest.FromAddress;
                message.FromName  = emailMessage.BaseRequest.FromDisplayName;
                var result = api.Send(message);
                if (result == null || result.Count == 0)
                {
                    throw new Exception("Email should be getting something back....");
                }
                if (result[0].Status == MailChimp.Types.Mandrill.Messages.Status.Invalid || result[0].Status == MailChimp.Types.Mandrill.Messages.Status.Bounced || result[0].Status == MailChimp.Types.Mandrill.Messages.Status.Rejected || result[0].Status == MailChimp.Types.Mandrill.Messages.Status.SoftBounced)
                {
                    throw new Exception("Some exception because email failed");
                }
                return(result[0].ID);
            }
        }
 public void Notify(string toNumber, string body)
 {
     var message = new MailChimp.Types.Mandrill.Messages.Message();
     message.Subject = "Message from Home Automation Platform";
     message.Text = body;
     message.FromEmail = this.fromAddress;
     this.client.Send(message);
 }
        public void SendEmail(MailMessage mailMessage, string[] tags = null)
        {
            try
            {
                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      = mailMessage.IsBodyHtml ? mailMessage.Body : null,
                    Text      = mailMessage.IsBodyHtml ? null : mailMessage.Body,
                };

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

                if (mailMessage.Bcc.Any())
                {
                    message.BccAddress = mailMessage.Bcc.First().Address;
                }
                if (tags != null)
                {
                    message.Tags = tags;
                }

                MVList <MailChimp.Types.Mandrill.Messages.SendResult> result = _mandrillApi.Send(message);
            }
            catch (Exception)
            {
                //TODO: Log
            }
        }