public MailerSendEmailParameters WithPersonalization(string email, object data) { if (!To.ToList().Any(r => string.Equals(r.Email, email, StringComparison.OrdinalIgnoreCase))) { throw new InvalidOperationException("The email must be in the list of recipients (to)"); } Personalizations.Add(new MailerSendEmailPersonalization(email, data)); return(this); }
public static async Task SendEmail(string to, string subject, string content) { //initialization of library Pepipost.PepipostClient client = new Pepipost.PepipostClient(); EmailController email = client.Email; EmailBody body = new EmailBody(); string apiKey = _options["PEPIPOST_API_KEY"]; //Add your Pepipost APIkey from panel here body.Personalizations = new List <Personalizations>(); Personalizations body_personalizations_0 = new Personalizations(); // List of Email Recipients body_personalizations_0.Recipient = to; //To/Recipient email address body_personalizations_0.Attributes = APIHelper.JsonDeserialize <Object>("{}"); body.Personalizations.Add(body_personalizations_0); body.From = new From(); // Email Header body.From.FromEmail = "*****@*****.**"; //Sender Email Address. Please note that the sender domain @exampledomain.com should be verified and active under your Pepipost account. body.From.FromName = "EMSfIIoT"; //Sender/From name //Email Body Content body.Subject = subject; //Subject of email body.Content = content; body.Settings = new Settings { Footer = 0, Clicktrack = 1, //Clicktrack for emails enable=1 | disable=0 Opentrack = 1, //Opentrack for emails enable=1 | disable=0 Unsubscribe = 1 //Unsubscribe for emails enable=1 | disable=0 }; SendEmailResponse result = await email.CreateSendEmailAsync(apiKey, body); try { if (result.Message.Contains("Error")) { Console.WriteLine("\n" + "Message ::" + result.Message + "\n" + "Error Code :: " + result.ErrorInfo.ErrorCode + "\n" + "Error Message ::" + result.ErrorInfo.ErrorMessage + "\n"); } else { Console.WriteLine("\n" + "Message ::" + result.Message); } } catch (APIException) { }; }
static void Main(string[] args) { Configuration.ApiKey = "api_key"; PepipostClient client = new PepipostClient(); MailSendController mailSend = client.MailSend; Send body = new Send(); body.From = new From(); body.From.Email = "*****@*****.**"; body.From.Name = "Pepipost"; body.Subject = "Pepipost Test Mail from SDK"; body.Content = new List <Content>(); Content body_content_0 = new Content(); body_content_0.Type = TypeEnum.HTML; body_content_0.Value = "<html><body>Hello, Welcome to Pepipost Family.<br>My name is [% name %].<br>my love is sending [% love %]</body> <br></html>"; body.Content.Add(body_content_0); body.Personalizations = new List <Personalizations>(); Personalizations body_personalizations_0 = new Personalizations(); body_personalizations_0.Attributes = APIHelper.JsonDeserialize <Object>("{\"name\":\"Pepi\",\"love\":\"Email\"}"); body_personalizations_0.Attachments = new List <Attachments>(); Attachments body_personalizations_0_attachments_0 = new Attachments(); body_personalizations_0_attachments_0.Content = "SGVsbG8sIHRoaXMgZmlsZSBpcyBhbiBpbmZvcm1hdGlvbmFsIGZpbGU6OiBTZW5kaW5nIGVtYWlscyB0byB0aGUgaW5ib3ggaXMgd2hhdCB3ZSBkbywgYnV0IHRoYXTigJlzIG5vdCB0aGUgb25seSByZWFzb24gd2h5IGRldmVsb3BlcnMgYW5kIGVudGVycHJpc2VzIGxvdmUgdXMuIFdlIGFyZSB0aGUgb25seSBFU1AgdGhhdCBkb2VzbuKAmXQgY2hhcmdlIGZvciBlbWFpbHMgb3BlbmVkLg=="; body_personalizations_0_attachments_0.Name = "personalized-file.txt"; body_personalizations_0.Attachments.Add(body_personalizations_0_attachments_0); body_personalizations_0.To = new List <EmailStruct>(); EmailStruct body_personalizations_0_to_0 = new EmailStruct(); body_personalizations_0_to_0.Name = "Vikram Sahu"; body_personalizations_0_to_0.Email = "*****@*****.**"; body_personalizations_0.To.Add(body_personalizations_0_to_0); body_personalizations_0.Cc = new List <EmailStruct>(); body_personalizations_0.Bcc = new List <EmailStruct>(); body.Personalizations.Add(body_personalizations_0); body.Tags = new List <string>(); body.Tags.Add("campaign"); const string dynamicURL = "https://api.pepipost.com"; //(pass if any other url is suggested) try { object result = mailSend.CreateGeneratethemailsendrequestAsync(body, dynamicURL).Result; Console.WriteLine(result); } catch (APIException e) { }; }