Ejemplo n.º 1
0
            public void Add_recipient_merge_vars_adds_by_recipient()
            {
                var model = new MandrillMessage();

                model.AddTo("*****@*****.**", "To #1");
                model.AddTo("*****@*****.**", "To #2", MandrillMailAddressType.Cc);
                model.AddTo("*****@*****.**");


                model.AddRcptMergeVars("*****@*****.**", "my-property", new { field = 1 });
                model.AddRcptMergeVars("*****@*****.**", "my-property", new { field = 2 });

                Assert.Equal(1, model.MergeVars.Single(m => m.Rcpt == "*****@*****.**").Vars.Single(v => v.Name == "my-property").Content.field);
                Assert.Equal(2, model.MergeVars.Single(m => m.Rcpt == "*****@*****.**").Vars.Single(v => v.Name == "my-property").Content.field);
                Assert.False(model.MergeVars.Any(m => m.Rcpt == "*****@*****.**"));
            }
        public static IList <MandrillSendMessageResponse> customSend(object model, MandrillTemplates template)
        {
            var api     = new MandrillApi("IRWMe1g1dCTrG6uOZEy7gQ");
            var message = new MandrillMessage();

            message.FromEmail = "*****@*****.**";
            message.AddTo("*****@*****.**");
            message.ReplyTo = "*****@*****.**";
            foreach (var prop in model.GetType().GetProperties())
            {
                var value = prop.GetValue(model, null);
                if (value != null)
                {
                    message.AddGlobalMergeVars(prop.Name, prop.GetValue(model, null).ToString());
                }
            }
            string templateName = string.Empty;

            switch (template)
            {
            case MandrillTemplates.Lead: templateName = "customer-lead"; break;

            case MandrillTemplates.Invoice: templateName = "customer-invoice"; break;

            default: break;
            }

            if (!string.IsNullOrEmpty(templateName))
            {
                var result = api.Messages.SendTemplate(message, templateName);
                return(result);
            }
            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Sends the email.
        /// </summary>
        /// <param name="email">The email.</param>
        /// <param name="mandrillTemplate">The mandrill template.</param>
        /// <param name="subjectLine">The subject line.</param>
        /// <param name="variables">The variables.</param>
        /// <param name="fromEmail">From email.</param>
        /// <param name="apiKey">The API key.</param>
        /// <exception cref="Exception">Customer Email cannot be null</exception>
        public void SendEmail(string email, string mandrillTemplate, string subjectLine,
                              Dictionary <string, object> variables, string fromEmail, string apiKey)
        {
            if (email == null)
            {
                throw new Exception("Customer Email cannot be null");
            }

            var api     = new MandrillApi(apiKey);
            var message = new MandrillMessage
            {
                FromEmail = fromEmail
            };

            message.AddTo(email);

            message.Merge         = true;
            message.MergeLanguage = MandrillMessageMergeLanguage.Handlebars;
            message.Subject       = subjectLine;

            message.ReplyTo = fromEmail;

            foreach (var variable in variables)
            {
                message.AddRcptMergeVars(email, variable.Key, variable.Value);
            }

            var result = api.Messages.SendTemplateAsync(message, mandrillTemplate).Result;
        }
Ejemplo n.º 4
0
            public void Add_recipient_merge_vars_adds_by_recipient()
            {
                var model = new MandrillMessage();

                model.AddTo("*****@*****.**", "To #1");
                model.AddTo("*****@*****.**", "To #2", MandrillMailAddressType.Cc);
                model.AddTo("*****@*****.**");


                model.AddRcptMergeVars("*****@*****.**", "my-property", new { field = 1 });
                model.AddRcptMergeVars("*****@*****.**", "my-property", new { field = 2 });

                Assert.Equal(1, model.MergeVars.Single(m => m.Rcpt == "*****@*****.**").Vars.Single(v => v.Name == "my-property").Content.field);
                Assert.Equal(2, model.MergeVars.Single(m => m.Rcpt == "*****@*****.**").Vars.Single(v => v.Name == "my-property").Content.field);
                Assert.DoesNotContain(model.MergeVars, m => m.Rcpt == "*****@*****.**");
            }
Ejemplo n.º 5
0
        private void Send(Lead model)
        {
            var api     = new MandrillApi("IRWMe1g1dCTrG6uOZEy7gQ");
            var message = new MandrillMessage();

            message.Subject   = "New lead";
            message.FromEmail = "*****@*****.**";
            message.AddTo("*****@*****.**");
            message.ReplyTo = "*****@*****.**";
            //supports merge var content as string
            message.AddGlobalMergeVars("Name", model.Name);
            message.AddGlobalMergeVars("LeadStatus", model.LeadStatus.ToString());
            message.AddGlobalMergeVars("DateCreated", model.DateCreated.ToShortDateString());
            message.AddGlobalMergeVars("DateUpdated", model.DateUpdated.ToShortDateString());
            message.AddGlobalMergeVars("EMAIL", model.Email);
            message.AddGlobalMergeVars("Skype", model.Skype);
            message.AddGlobalMergeVars("Phone", model.Phone);
            message.AddGlobalMergeVars("Company", model.Company);
            message.AddGlobalMergeVars("Skype", model.Skype);
            message.AddGlobalMergeVars("ProjectDescription", model.ProjectDescription);
            message.AddGlobalMergeVars("ProjectStart", model.ProjectStart);
            message.AddGlobalMergeVars("ProjectDeadline", model.ProjectDeadline);
            //template should be created
            var result = api.Messages.SendTemplate(message, "jarboo-new-lead");
        }
Ejemplo n.º 6
0
        public async Task <List <MailingResult> > SendEmailsAsync(Message message)
        {
            var email = new MandrillMessage()
            {
                FromEmail = message.FromEmail,
                FromName  = message.FromName,
                Subject   = message.Subject,
                Html      = message.Body
            };

            foreach (var to in message.To)
            {
                email.AddTo(to.Key, to.Value, MandrillMailAddressType.To);
            }
            foreach (var cc in message.Cc)
            {
                email.AddTo(cc.Key, cc.Value, MandrillMailAddressType.Cc);
            }
            foreach (var bcc in message.Bcc)
            {
                email.AddTo(bcc.Key, bcc.Value, MandrillMailAddressType.Bcc);
            }

            foreach (var attachment in message.Attachments)
            {
                email.Attachments.Add(new MandrillAttachment()
                {
                    Name    = attachment.Name,
                    Type    = attachment.Type,
                    Content = attachment.Content,
                });
            }

            var result = await _api.SendAsync(email);

            return(result.Select(x => new MailingResult()
            {
                Id = x.Id,
                Email = x.Email,
                RejectReason = x.RejectReason,
                Status = x.Status.ToString()
            }).ToList());
        }
        private void Send(ContactViewModel model)
        {
            var api     = new MandrillApi("IRWMe1g1dCTrG6uOZEy7gQ");
            var message = new MandrillMessage();

            message.FromEmail = "*****@*****.**";
            message.AddTo("*****@*****.**");
            message.ReplyTo = "*****@*****.**";
            //supports merge var content as string

            message.AddGlobalMergeVars("EMAIL", model.Email);
            message.AddGlobalMergeVars("MESSAGE", model.Message);
            var result = api.Messages.SendTemplate(message, "jarboo-contact-form");
        }
Ejemplo n.º 8
0
        public override async Task SendEmailAsync(
            string subject,
            string message,
            string toEmail      = null,
            string fromEmail    = null,
            string replyToEmail = null)
        {
            MandrillApi     mandrillApi;
            MandrillMessage mandrillMessage;
            IList <MandrillSendMessageResponse> result = null;

            try
            {
                fromEmail    = string.IsNullOrEmpty(fromEmail) ? _fromEmail : fromEmail;
                replyToEmail = string.IsNullOrEmpty(replyToEmail) ? fromEmail : replyToEmail;

                mandrillApi = new MandrillApi(_password);


                mandrillMessage           = new MandrillMessage();
                mandrillMessage.Subject   = subject;
                mandrillMessage.FromEmail = fromEmail;
                mandrillMessage.AddTo(toEmail);
                mandrillMessage.ReplyTo = replyToEmail;

                mandrillMessage.Text = message;

                result = await mandrillApi.Messages.SendAsync(mandrillMessage);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            finally
            {
                mandrillApi     = null;
                mandrillMessage = null;

                if (result != null)
                {
                    result.Clear();
                    result = null;
                }
            }
        }
        public ActionResult ResendComfomationEmail(int OrderIdInput)
        {
            var orderCount = "99";


            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
            {
                using (SqlCommand command = new SqlCommand("SPU_HT_Customer_Service_Is_Valid_OrderId"))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@OrderId", OrderIdInput);

                    command.Connection = connection;
                    connection.Open();
                    SqlDataReader myReader = command.ExecuteReader();
                    while (myReader.Read())
                    {
                        orderCount = myReader["OrderCount"].ToString();
                    }

                    connection.Close();
                }
            }

            if (orderCount == "0" || orderCount == "99")
            {
                return(RedirectToAction("ResendComformation", "CustomerService", new { error = true }));
            }


            var api     = new MandrillApi("mwikOWlc9HLroBSaEpQkhw");
            var message = new MandrillMessage();

            var title         = "";
            var firstName     = "";
            var customerId    = "";
            var doornumber    = "";
            var address1      = "";
            var address2      = "";
            var townCity      = "";
            var county        = "";
            var postcode      = "";
            var orderDateTime = "";
            var paymentType   = "";
            var tPrice        = "";
            var dPrice        = "";
            var customerEmail = "";


            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
            {
                using (SqlCommand command = new SqlCommand("SPU_HT_Customer_Service_Resend_Email_Info"))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@OrderId", OrderIdInput);

                    command.Connection = connection;
                    connection.Open();
                    SqlDataReader myReader = command.ExecuteReader();
                    while (myReader.Read())
                    {
                        title         = myReader["title"].ToString();
                        firstName     = myReader["firstname"].ToString();
                        customerId    = myReader["customerid"].ToString();
                        doornumber    = myReader["buildingnumber"].ToString();
                        address1      = myReader["streetaddress1"].ToString();
                        address2      = myReader["streetaddress2"].ToString();
                        townCity      = myReader["TownCity"].ToString();
                        county        = myReader["county"].ToString();
                        postcode      = myReader["postcode"].ToString();
                        orderDateTime = myReader["orderdate"].ToString();
                        paymentType   = myReader["paymentmethod"].ToString();
                        tPrice        = myReader["TotalValue"].ToString();
                        dPrice        = myReader["DeliveryValue"].ToString();
                        customerEmail = myReader["emailaddress"].ToString();
                    }

                    connection.Close();
                }
            }

            var formatedTime           = ManipulateDateTime(orderDateTime);
            var formaterStreetAddress1 = doornumber + "," + address1;
            var formatedPaymentType    = "Card";
            var formatedorders         = ManipulateOrderItems(OrderIdInput);

            //------populating template email------------//
            message.FromEmail = "*****@*****.**";
            message.AddTo(customerEmail);
            message.AddTo("*****@*****.**");
            //message.AddTo("*****@*****.**"); // testing to see if it comes through
            message.ReplyTo = "*****@*****.**";
            message.Subject = "Hochanda Order Confirmation: " + "#" + OrderIdInput;
            message.AddGlobalMergeVars("customer-invoice", DateTime.Now.ToShortDateString());


            //-------populate email for sending-----------//
            message.AddGlobalMergeVars("TITLE", title);
            message.AddGlobalMergeVars("FIRSTNAME", firstName);
            message.AddGlobalMergeVars("ORDERNUMBER", OrderIdInput.ToString());
            message.AddGlobalMergeVars("ACCOUNTID", customerId);
            message.AddGlobalMergeVars("ADDRESSNUMBER", formaterStreetAddress1);
            message.AddGlobalMergeVars("ADDRESSLINE2", address2);
            message.AddGlobalMergeVars("TOWNCITY", townCity);
            message.AddGlobalMergeVars("COUNTY", county);
            message.AddGlobalMergeVars("POSTCODE", postcode);
            message.AddGlobalMergeVars("ACCOUNTLINK", "http://www.hochanda.com/MyAccount.aspx");
            message.AddGlobalMergeVars("ORDERITEMS", formatedorders);
            message.AddGlobalMergeVars("ORDERTIMESTAMP", formatedTime);
            message.AddGlobalMergeVars("PAYMENTTYPE", formatedPaymentType);
            message.AddGlobalMergeVars("TOTALPRICE", tPrice);
            message.AddGlobalMergeVars("DELIVERYPRICE", dPrice);
            var rs = api.Messages.SendTemplate(message, "customer-invoice-success");

            return(RedirectToAction("ResendComformation", "CustomerService", new { sucess = true }));
        }