var msg = new SendGridMessage(); msg.Subject = "Hello {{name}}"; msg.PlainTextContent = "Hi {{name}}, your order {{order}} is on its way."; msg.AddSubstitution("{{name}}", "John"); msg.AddSubstitution("{{order}}", "12345"); // Rest of the code to send the email using SendGrid library // Package library: Sendgrid
var msg = new SendGridMessage(); msg.Subject = "Hello {{name}}"; msg.PlainTextContent = "Here are the details of your order {{order}}:\n\n{{details}}"; var substitutions = new DictionaryThis example shows how to use the `AddSubstitution` method with a dictionary to add multiple substitution tags to a message. We create a dictionary with the tags and replacement values and then iterate over each item in the dictionary and call the method to add them to the message. The resulting email message will have personalized content for each recipient based on the values specified in the dictionary. Package library: Sendgrid{ { "{{name}}", "Jane" }, { "{{order}}", "67890" }, { "{{details}}", "Product: Phone\nQuantity: 1\nPrice: $1000" } }; foreach(var substitution in substitutions) { msg.AddSubstitution(substitution.Key, substitution.Value); } // Rest of the code to send the email using SendGrid library // Package library: Sendgrid