using System; using System.Collections.Generic; using System.Web.Script.Serialization; using SendGrid.Helpers.Mail; namespace Example { internal class Example { private static void Main() { // v3 Mail Helper HelloEmail(); // this will actually send an email KitchenSink(); // this will only send an email if you set SandBox Mode to false // v3 Web API ApiKeys(); } private static void HelloEmail() { String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); dynamic sg = new SendGrid.SendGridAPIClient(apiKey, "https://3wyb2hp7emnqja6ys.stoplight-proxy.io"); Email from = new Email("dx@sendgrid.com"); String subject = "Hello World from the SendGrid CSharp Library"; Email to = new Email("elmer.thomas@sendgrid.com"); Content content = new Content("text/plain", "Textual content"); Mail mail = new Mail(from, subject, to, content); Email email = new Email("elmer.thomas+add_second_email@sendgrid.com"); mail.Personalization[0].AddTo(email); String ret = mail.Get(); string requestBody = ret; dynamic response = sg.client.mail.send.beta.post(requestBody: requestBody); Console.WriteLine(response.StatusCode); Console.WriteLine(response.ResponseBody.ReadAsStringAsync().Result); Console.WriteLine(response.ResponseHeaders.ToString()); Console.WriteLine(ret); Console.ReadLine(); } private static void KitchenSink() { String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); dynamic sg = new SendGrid.SendGridAPIClient(apiKey, "https://3wyb2hp7emnqja6ys.stoplight-proxy.io"); Mail mail = new Mail(); Email email = new Email(); email.Name = "DX"; email.Address = "dx@sendgrid.com"; mail.From = email; mail.Subject = "Hello World from the SendGrid CSharp Library"; Personalization personalization = new Personalization(); email = new Email(); email.Name = "Elmer Thomas"; email.Address = "elmer.thomas@sendgrid.com"; personalization.AddTo(email); email = new Email(); email.Name = "Matt Bernier"; email.Address = "matt.bernier@sendgrid.com"; personalization.AddCc(email); email = new Email(); email.Name = "Eric Shallock"; email.Address = "eric.shallock@sendgrid.com"; personalization.AddCc(email); email = new Email(); email.Name = "Elmer Thomas Secret"; email.Address = "elmer.thomas + secret@sengrid.com"; personalization.AddBcc(email); email = new Email(); email.Name = "Elmer Thomas Secret 2"; email.Address = "elmer.thomas+secret@elmer.thomas.com"; personalization.AddBcc(email); personalization.Subject = "Thank you for signing up, %name%"; personalization.AddHeader("X-Test", "True"); personalization.AddHeader("X-Mock", "True"); personalization.AddSubstitution("%name%", "Elmer"); personalization.AddSubstitution("%city%", "Moreno Valley"); personalization.AddCustomArgs("marketing", "false"); personalization.AddCustomArgs("transactional", "true"); personalization.SendAt = 1461775051; mail.AddPersonalization(personalization); personalization = new Personalization(); email = new Email(); email.Name = "Elmer Thomas"; email.Address = "elmer.thomas@gmail.com"; personalization.AddTo(email); email = new Email(); email.Name = "Matt Bernier"; email.Address = "matt.bernier@sendgrid.com"; personalization.AddCc(email); email = new Email(); email.Name = "Eric Shallock"; email.Address = "eric.shallock@sendgrid.com"; personalization.AddCc(email); email = new Email(); email.Name = "Elmer Thomas Secret"; email.Address = "elmer.thomas + secret@sengrid.com"; personalization.AddBcc(email); email = new Email(); email.Name = "Elmer Thomas Secret 2"; email.Address = "elmer.thomas+secret@elmer.thomas.com"; personalization.AddBcc(email); personalization.Subject = "Thank you for signing up, %name%"; personalization.AddHeader("X-Test", "True"); personalization.AddHeader("X-Mock", "True"); personalization.AddSubstitution("%name%", "Elmer"); personalization.AddSubstitution("%city%", "Moreno Valley"); personalization.AddCustomArgs("marketing", "false"); personalization.AddCustomArgs("transactional", "true"); personalization.SendAt = 1461775051; mail.AddPersonalization(personalization); Content content = new Content(); content.Type = "text/plain"; content.Value = "Textual content"; mail.AddContent(content); content = new Content(); content.Type = "text/html"; content.Value = "
HTML content"; mail.AddContent(content); content = new Content(); content.Type = "text/calendar"; content.Value = "Party Time!!"; mail.AddContent(content); Attachment attachment = new Attachment(); attachment.Content = "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12"; attachment.Type = "application/pdf"; attachment.Filename = "balance_001.pdf"; attachment.Disposition = "attachment"; attachment.ContentId = "Balance Sheet"; mail.AddAttachment(attachment); attachment = new Attachment(); attachment.Content = "BwdW"; attachment.Type = "image/png"; attachment.Filename = "banner.png"; attachment.Disposition = "inline"; attachment.ContentId = "Banner"; mail.AddAttachment(attachment); mail.TemplateId = "13b8f94f-bcae-4ec6-b752-70d6cb59f932"; mail.AddHeader("X-Day", "Monday"); mail.AddHeader("X-Month", "January"); mail.AddSection("%section1", "Substitution for Section 1 Tag"); mail.AddSection("%section2", "Substitution for Section 2 Tag"); mail.AddCategory("customer"); mail.AddCategory("vip"); mail.AddCustomArgs("campaign", "welcome"); mail.AddCustomArgs("sequence", "2"); ASM asm = new ASM(); asm.GroupId = 3; List