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; }
public async void Can_send_template_dynamic() { var message = new MandrillMessage { 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.ToShortDateString()); message.AddGlobalMergeVars("PRODUCTS", item1, item2); var result = await Api.Messages.SendTemplateAsync(message, TestTemplateName); result.Should().HaveCount(2); result[0].Status.Should().Be(MandrillSendMessageResponseStatus.Sent); result[0].Id.Should().NotBeEmpty(); result[1].Id.Should().NotBeEmpty(); result[1].Status.Should().Be(MandrillSendMessageResponseStatus.Sent); }
public async void Can_send_template_object_list() { var message = new MandrillMessage { 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.ToShortDateString()); message.AddRcptMergeVars("*****@*****.**", "PRODUCTS", data1); message.AddRcptMergeVars("*****@*****.**", "PRODUCTS", data2); var result = await Api.Messages.SendTemplateAsync(message, TestTemplateName); result.Should().HaveCount(2); result[0].Status.Should().Be(MandrillSendMessageResponseStatus.Sent); result[0].Id.Should().NotBeEmpty(); result[1].Id.Should().NotBeEmpty(); result[1].Status.Should().Be(MandrillSendMessageResponseStatus.Sent); }
public async void Can_send_template() { var message = new MandrillMessage { 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", DateTime.UtcNow.ToShortDateString()); 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); result[0].Status.Should().NotBe(MandrillSendMessageResponseStatus.Invalid); result[0].Status.Should().NotBe(MandrillSendMessageResponseStatus.Rejected); result[0].Id.Should().NotBeEmpty(); result[1].Id.Should().NotBeEmpty(); result[1].Status.Should().NotBe(MandrillSendMessageResponseStatus.Invalid); result[1].Status.Should().NotBe(MandrillSendMessageResponseStatus.Rejected); }
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"); }
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"); }