<%datetime%>
SendGrid テンプレートで変数を定義しました。この命名規則により、既に配置され<%subject%>
ている件名に従うことにしました。例にはさまざまな変数の命名規則があります: https://github.com/sendgrid/sendgrid-csharp/blob/master/SendGrid/Example/Example.cs#L41は-name-
and-city-
を使用します/sendgrid-csharp/blob/master/SendGrid/Example/Example.cs#L157は%name%
とを使用し%city%
ます。
変数の置換は単純なパターン マッチングに基づいているため、これらの例の対応するテンプレートにはまったく同じ文字列が含まれていると思います。なんらかの理由で、これまでのところうまくいきません。
string sendGridApiKey = ConfigurationManager.AppSettings["SendGridApiKey"].ToString();
var sendGrid = new SendGridAPIClient(sendGridApiKey);
string emailFrom = ConfigurationManager.AppSettings["EmailFrom"].ToString();
Email from = new Email(emailFrom);
string subject = "Supposed to be replaced. Can I get rid of this somehow then?";
string emaiTo = ConfigurationManager.AppSettings["EmailTo"].ToString();
Email to = new Email(emaiTo);
Content content = new Content("text/html", "Supposed to be replaced by the template. Can I get rid of this somehow then?");
Mail mail = new Mail(from, subject, to, content);
mail.TemplateId = "AC6A01BB-CFDF-45A7-BA53-8ECC54FD89DD";
mail.Personalization[0].AddSubstitution("<%subject%>", $"Your Report on {shortDateTimeStr}");
mail.Personalization[0].AddSubstitution("<%datetime%>", longDateTimeStr);
// Some code adds several attachments here
var response = await sendGrid.client.mail.send.post(requestBody: mail.Get());
リクエストは受け入れられて処理されましたが、受信したメールにはまだ件名が含まれています
「交換のはずです。では、これをどうにか取り除くことはできますか?」
本文は未加工のテンプレート コンテンツに置き換えられますが、変数も置き換えられません。私は何を間違っていますか?