/// <summary> /// This feature allows you to create a message template, and specify different replacement /// strings for each specific recipient /// </summary> public void AddSubstitutionValues() { //create a new message object var message = new SendGrid(); //set the message recipients foreach (var recipient in _to) { message.AddTo(recipient); } //set the sender message.From = new MailAddress(_from); //set the message body message.Text = "Hi %name%! Pleased to meet you!"; //set the message subject message.Subject = "Testing Substitution Values"; //This replacement key must exist in the message body var replacementKey = "%name%"; //There should be one value for each recipient in the To list var substitutionValues = new List<String> {"Mr Foo", "Mrs Raz"}; message.AddSubstitution(replacementKey, substitutionValues); //create an instance of the SMTP transport mechanism var transportInstance = new Web(new NetworkCredential(_username, _password)); //enable bypass list management message.EnableBypassListManagement(); //send the mail transportInstance.Deliver(message); }