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 void SendWelcomeEmail(IUser user) { // CultureUsed = "en-MY"; var pathToTemplates = HttpContext.Current.Server.MapPath("/Modules/Teeyoot.Module/Content/message-templates/"); var record = _settingsService.GetAllSettings().List().FirstOrDefault(); var api = new MandrillApi(record.ApiKey); var mandrillMessage = new MandrillMessage { MergeLanguage = MandrillMessageMergeLanguage.Handlebars, FromEmail = "*****@*****.**", FromName = "Teeyoot", Subject = _mailSubjectService .GetMailSubject("welcome-template", CultureUsed) //"Teeyoot welcomes you onboard!" }; var emails = new List <MandrillMailAddress> { new MandrillMailAddress(user.Email, "user") }; mandrillMessage.To = emails; var request = HttpContext.Current.Request; mandrillMessage.AddRcptMergeVars(user.Email, "Url", request.Url.Scheme + "://" + request.Url.Authority + request.ApplicationPath.TrimEnd('/') + "/"); var baseUrl = ""; baseUrl = request.Url.Scheme + "://" + request.Url.Authority + request.ApplicationPath.TrimEnd('/') + "/"; mandrillMessage.AddRcptMergeVars(user.Email, "VideoPreviewUrl", baseUrl + "/Media/Default/images/video_thumbnail_521x315.jpg/"); var text = System.IO.File.ReadAllText(pathToTemplates + "en-MY" + "/welcome-template.html"); mandrillMessage.Html = text; var res = SendTmplMessage(api, mandrillMessage); }
public void FillMessageMergeVars(MandrillMessage message, Module.Models.LinkOrderCampaignProductRecord record) { var products = new Dictionary <string, object> { { "quantity", record.Count }, { "name", record.CampaignProductRecord.ProductRecord.Name }, { "description", record.CampaignProductRecord.ProductRecord.Details }, { "price", record.CampaignProductRecord.Price }, { "total_price", record.OrderRecord.TotalPrice } }; message.AddRcptMergeVars(record.OrderRecord.Email, "FNAME", record.OrderRecord.FirstName); message.AddRcptMergeVars(record.OrderRecord.Email, "LNAME", record.OrderRecord.LastName); message.AddRcptMergeVars(record.OrderRecord.Email, "CITY", record.OrderRecord.City); message.AddRcptMergeVars(record.OrderRecord.Email, "STATE", record.OrderRecord.State); message.AddRcptMergeVars(record.OrderRecord.Email, "COUNTRY", record.OrderRecord.Country); if (record.OrderRecord.TotalPriceWithPromo > 0.0) { message.AddRcptMergeVars(record.OrderRecord.Email, "TOTALPRICE", record.OrderRecord.TotalPriceWithPromo.ToString()); } else { message.AddRcptMergeVars(record.OrderRecord.Email, "TOTALPRICE", record.OrderRecord.TotalPrice.ToString()); } message.AddRcptMergeVars(record.OrderRecord.Email, "PRODUCTS", products); }
/// <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; }
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 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 == "*****@*****.**"); }
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); }