本文介绍了如何通过API C#和模板将自定义变量添加到SendGrid电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何将变量添加到已在sendgrid模板引擎中创建的现有模板(例如:动态Web链接或名称)中,我不确定如何使用SendGrid C#.NET库执行此操作.我想知道是否有人可以帮助我.

I am trying to figure out how to add variables to existing template (example: Web Link Or Name dynamically) which has been created in sendgrid template engine, I am unsure how to do this using the SendGrid C# .NET libraries. I am wondering if anyone could help me.

// Create the email object first, then add the properties.
SendGridMessage myMessage = new SendGridMessage();

myMessage.AddTo("[email protected]");
myMessage.From = new MailAddress("[email protected]", "Mr test");
myMessage.Subject = " ";

var timestamp = DateTime.Now.ToString("HH:mm:ss tt");
myMessage.Html = "<p></p> ";

myMessage.EnableTemplate("<p> <% body %> Hello</p>");
myMessage.EnableTemplateEngine("9386b483-8ad4-48c2-9ee3-afc7618eb56a");
var identifiers = new Dictionary<String, String>();
identifiers["USER_FULLNAME"] = "Jimbo Jones";
identifiers["VERIFICATION_URL"] = "www.google.com";
myMessage.AddUniqueArgs(identifiers);

// Create credentials, specifying your user name and password.
var credentials = new NetworkCredential("username", "password");
// Create an Web transport for sending email.
var transportWeb = new Web(credentials);
// Send the email.
transportWeb.Deliver(myMessage);

推荐答案

我找到了解决方法:

replacementKey = "*|VERIFICATION_URL|*";
substitutionValues = new List<string> { VERIFICATION_URL };

myMessage.AddSubstitution(replacementKey, substitutionValues);

这篇关于如何通过API C#和模板将自定义变量添加到SendGrid电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 04:20