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");
        }
Exemple #2
0
            public async Task Can_send_template_dynamic()
            {
                var message = new MandrillMessage
                {
                    FromEmail = FromEmail,
                    Subject   = "test",
                    Tags      = new List <string>()
                    {
                        "test-send-template", "mandrill-net", "handlebars"
                    },
                    MergeLanguage = MandrillMessageMergeLanguage.Handlebars,
                    To            = new List <MandrillMailAddress>()
                    {
                        new MandrillMailAddress("*****@*****.**", "Test1 User"),
                        new MandrillMailAddress("*****@*****.**", "Test2 User")
                    },
                };

                dynamic item1 = new ExpandoObject();

                item1.sku         = "APL54";
                item1.name        = "apples";
                item1.description = "Red Dynamic Apples";
                item1.price       = 0.22;
                item1.qty         = 9;
                item1.ordPrice    = 1.98;
                item1.tags        = new { id = "tag1", enabled = true };


                dynamic item2 = new ExpandoObject();

                item2.sku         = "ORA54";
                item2.name        = "oranges";
                item2.description = "Dynamic Oranges";
                item2.price       = 0.33;
                item2.qty         = 8;
                item2.ordPrice    = 2.00;
                item2.tags        = new { id = "tag2", enabled = false };


                message.AddGlobalMergeVars("ORDERDATE", DateTime.UtcNow.ToString("d"));
                message.AddGlobalMergeVars("PRODUCTS", new[] { item1, item2 });

                var result = await Api.Messages.SendTemplateAsync(message, TestTemplateName);

                result.Should().HaveCount(2);
                AssertResults(result);
            }
Exemple #3
0
            public async Task Can_send_template()
            {
                var message = new MandrillMessage
                {
                    FromEmail = FromEmail,
                    Subject   = "test",
                    Tags      = new List <string>()
                    {
                        "test-send-template", "mandrill-net"
                    },
                    To = new List <MandrillMailAddress>()
                    {
                        new MandrillMailAddress("*****@*****.**", "Test1 User"),
                        new MandrillMailAddress("*****@*****.**", "Test2 User")
                    },
                };

                message.AddGlobalMergeVars("ORDERDATE", string.Format("{0:d}", DateTime.UtcNow));
                message.AddRcptMergeVars("*****@*****.**", "INVOICEDETAILS", "invoice for [email protected]");
                message.AddRcptMergeVars("*****@*****.**", "INVOICEDETAILS", "invoice for [email protected]");

                var result = await Api.Messages.SendTemplateAsync(message, TestTemplateName);

                result.Should().HaveCount(2);
                AssertResults(result);
            }
        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);
        }
Exemple #5
0
        public static void SendEmailWithTemplate(string apiKey, string header, string body, string emailTo, ordertemplate orderTemplate)
        {
            /*
             * Uncomment namespace from top
             * <add key="MandrilAPIKey" value="fake"/>
             */
            var api     = new MandrillApi(apiKey);
            var message = new MandrillMessage(CommonConstant.EmailFrom, emailTo,
                                              header, body);

            message.AddGlobalMergeVars("NAME", orderTemplate.Name);
            message.AddGlobalMergeVars("ORDERNO", orderTemplate.OrderNo);
            message.AddGlobalMergeVars("CONTACT", orderTemplate.Contact);
            message.AddGlobalMergeVars("ADDRESS", orderTemplate.Address);
            message.AddGlobalMergeVars("CITY", orderTemplate.Name);
            message.AddGlobalMergeVars("STATE", orderTemplate.Name);
            message.AddGlobalMergeVars("ZIPCODE", orderTemplate.Name);
            message.AddGlobalMergeVars("ORDERLIST", orderTemplate.OrderList);
            message.MergeLanguage = MandrillMessageMergeLanguage.Handlebars;
            var result = api.Messages.SendTemplateAsync(message, "OrderSuccessTemplate");

            result.Wait();
            var checkResult = result.Result;
        }
Exemple #6
0
            public async Task Can_send_template_object_list()
            {
                var message = new MandrillMessage
                {
                    FromEmail = FromEmail,
                    Subject   = "test",
                    Tags      = new List <string>()
                    {
                        "test-send-template", "mandrill-net", "handlebars"
                    },
                    MergeLanguage = MandrillMessageMergeLanguage.Handlebars,
                    To            = new List <MandrillMailAddress>()
                    {
                        new MandrillMailAddress("*****@*****.**", "Test1 User"),
                        new MandrillMailAddress("*****@*****.**", "Test2 User")
                    },
                };


                var data1 = new[]
                {
                    new Dictionary <string, object>
                    {
                        { "sku", "APL43" },
                        { "name", "apples" },
                        { "description", "Granny Smith Apples" },
                        { "price", 0.20 },
                        { "qty", 8 },
                        { "ordPrice", 1.60 },
                    },
                    new Dictionary <string, object>
                    {
                        { "sku", "ORA44" },
                        { "name", "Oranges" },
                        { "description", "Blood Oranges" },
                        { "price", 0.30 },
                        { "qty", 3 },
                        { "ordPrice", 0.93 },
                    }
                };

                var data2 = new[]
                {
                    new Dictionary <string, object>
                    {
                        { "sku", "APL54" },
                        { "name", "apples" },
                        { "description", "Red Delicious Apples" },
                        { "price", 0.22 },
                        { "qty", 9 },
                        { "ordPrice", 1.98 },
                    },
                    new Dictionary <string, object>
                    {
                        { "sku", "ORA53" },
                        { "name", "Oranges" },
                        { "description", "Sunkist Oranges" },
                        { "price", 0.20 },
                        { "qty", 1 },
                        { "ordPrice", 0.20 },
                    }
                };

                message.AddGlobalMergeVars("ORDERDATE", DateTime.UtcNow.ToString("d"));
                message.AddRcptMergeVars("*****@*****.**", "PRODUCTS", data1);
                message.AddRcptMergeVars("*****@*****.**", "PRODUCTS", data2);

                var result = await Api.Messages.SendTemplateAsync(message, TestTemplateName);

                result.Should().HaveCount(2);
                AssertResults(result);
            }
        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 }));
        }
Exemple #8
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");
        }