public static async void SendMessage(string destination, EmailTemplate template, Dictionary <string, object> mailParameters, Action <string> callback) { SendwithusClient.ApiKey = liveApiKey; var link = new Dictionary <string, string> { { "url", "https://www.sendiwthus.com" } }; mailParameters.Add("link", link); foreach (var address in destination.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { try { var recipient = new EmailRecipient(address.Trim()); var email = new Sendwithus.Email(template.Value, mailParameters, recipient); var response = await email.Send(); callback?.Invoke(response.status + ":" + response.receipt_id); } catch { // ignored - no email } } }
private async Task <List <EmailResponse> > SendMessage(string templateId, Dictionary <string, object> templateData, List <EmailRecipient> recipients) { List <EmailResponse> responses = new List <EmailResponse>(); var templateString = JsonConvert.SerializeObject(templateData); if (!string.IsNullOrWhiteSpace(templateId) && templateData != null && recipients != null) { foreach (var recipient in recipients) { var personalisedData = JsonConvert.DeserializeObject <Dictionary <string, object> >(templateString); personalisedData.Add("Recipient", recipient.name); var email = new Sendwithus.Email(templateId, personalisedData, recipient); try { var emailResponse = await email.Send(); responses.Add(emailResponse); } catch (AggregateException ex) { responses.Add(new EmailResponse() { success = false, status = ex.Message }); } } } return(responses); }
public static async void SendMessage(string destination, EmailTemplate template, Dictionary <string, object> mailParameters, Action <string> callback) { SendwithusClient.ApiKey = liveApiKey; var link = new Dictionary <string, string> { { "url", "https://www.sendiwthus.com" } }; mailParameters.Add("link", link); var recipient = new EmailRecipient(destination); var email = new Sendwithus.Email(template.Value, mailParameters, recipient); var response = await email.Send(); callback?.Invoke(response.status + ":" + response.receipt_id); }