private static async Task Main(string[] args) { SendGridMessage aMessage = new SendGridMessage { From = new EmailAddress("*****@*****.**", "James Brown"), //this is nice for property init, but it directly exposes the storage mechanism (List<EmailAddrress>) which some people would frown upon https://en.wikipedia.org/wiki/Law_of_Demeter To = { new EmailAddress("*****@*****.**", "Forgot Him"), new EmailAddress("*****@*****.**", "That Guy"), new EmailAddress("*****@*****.**", "Other Gal") }, Subject = "Free bird", PlainTextContent = new TextContent("I like eggs"), HtmlContent = new HtmlContent("I <string>really</string> like eggs"), Priority = MailPriority.High }; //this protectts that internal list by restricting operations on it to a known method. Could also include RemoveRecipient aMessage.AddRecipient(new EmailAddress("*****@*****.**", "Forgot Him")); aMessage.AddRecipient(new EmailAddress("*****@*****.**", "That Guy")); aMessage.AddRecipient(new EmailAddress("*****@*****.**", "Other Gal")); //OR aMessage.AddRecipients(new List <EmailAddress> { new EmailAddress("*****@*****.**", "Forgot Him"), new EmailAddress("*****@*****.**", "That Guy"), new EmailAddress("*****@*****.**", "Other Gal") }); // access to that internal list without the ability to modify it directly foreach (EmailAddress aMessageRecipient in aMessage.Recipients) { Console.WriteLine($"Sending to {aMessageRecipient.Name} [{aMessageRecipient.Email}]"); } //maybe this EmailAttachment anAttachment = SomeAttachmentHelperThing.FromFile(Path.GetFullPath(@"C:\temp\image.jpg")); aMessage.AddAttachment(anAttachment); //finally, send SendGridClient aClient = new SendGridClient("API-KEY-MADNESS"); SendResult aResult = await aClient.SendAsync(aMessage); Console.WriteLine($"Result : {aResult}"); }
public void AddAttachment(EmailAttachment anAttachment) { throw new NotImplementedException(); }