如何将动态数据传递到 sendgrid webapp 上设计的电子邮件模板? :-|发送网格

发布于 2024-09-28 21:45:33 字数 352 浏览 1 评论 0原文

我将 sendgrid 电子邮件服务与我的示例应用程序集成。 &还可以向用户发送电子邮件。

但是如何将动态数据传递到sendGrid Web应用程序上的电子邮件模板设计? 有没有办法将动态数据发送到在sendgrid上设计的电子邮件模板?

对于前。我在 sendgrid 上设计了欢迎电子邮件模板。 &我想通过 使用 java 将动态数据添加到此模板,即 UserName 、 emailId 、 City 等 代码 ? 当任何用户注册我的应用程序时,我想发送欢迎信息 发送电子邮件给该用户。包含用户信息,如 UserName 、 emailId 、 City 等等..通过我们的数据库。

该怎么办 ?怎么办?

I integrated sendgrid email service with my sample application.
& also able to send email to user.

But how to pass dynamic data to Email template design on sendGrid webapp?
is there any way to send dynamic data to email template designed on sendgrid?

for ex. I designed Welcome email template on sendgrid. & I want to pass
dynamic data to this template i.e UserName , emailId, City etc.. using java
code ?
when any user registered with my application then I want to send welcome
email to that user. with information of user like UserName , emailId, City
etc.. through our database.

What to do ? How to do ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情定在深秋 2024-10-05 21:45:33

您应该查看 SMTPAPI。通过在邮件中添加 X-SMTPAPI 标头,您可以

  1. 控制 SendGrid 帐户的设置(即 动态更改过滤器设置
  2. 在单个 SMTP 事务中发送至最多 1000 个收件人地址 (SMTPAPI 至:数组
  3. 在邮件正文中执行类似邮件合并的替换 (SMTPAPI 子:关联数组

最后,假设您直接通过我们的 SMTP 或 Web API 发送电子邮件。如果您使用我们的时事通讯功能,则可以使用 自定义标签进行类似邮件合并的替换 在新闻通讯模板中。

——乔·

发送网格

Instead of focusing on substitution via the Email Template application (which is not possible), You should take a look at the SMTPAPI. By adding a X-SMTPAPI header in your message, you can

  1. Control the settings of your SendGrid account (i.e. change filter settings on the fly)
  2. Send to up to 1000 recipient addresses in a single SMTP transaction (SMTPAPI To: Array)
  3. Perform mail-merge like substitutions in the mail body (SMTPAPI Sub: Associative Array)

Finally this is assuming you are sending email directly via our SMTP or Web API. If you are using our newsletter feature, mail-merge like substitution is possible by using Custom Tags in the newsletter template.

-- Joe

SendGrid

恬淡成诗 2024-10-05 21:45:33

我认为现在可以,通过添加替换 在选项中键入。我还添加了 to 键,因为该键是强制性的。

$request_body = json_decode('{
  "personalizations": [
    {
      "substitutions": {
        "-first_name-": "John",
        "-last_name-": "Doe"
      },
      "to": [
        {
          "email": "[email protected]",
          "name": "John Doe"
        }
      ]
    }
  }
}');
$response = $sg->client->mail()->send()->post($request_body);
echo $response->statusCode();
echo $response->body();
print_r($response->headers());

Sendgrid 中的模板如下所示:

Dear -first_name- -last_name-,

Foo bar...

Kind Regards

I think it is possible now, by adding a substitutions key in the options. I also added the to key because that one is mandatory.

$request_body = json_decode('{
  "personalizations": [
    {
      "substitutions": {
        "-first_name-": "John",
        "-last_name-": "Doe"
      },
      "to": [
        {
          "email": "[email protected]",
          "name": "John Doe"
        }
      ]
    }
  }
}');
$response = $sg->client->mail()->send()->post($request_body);
echo $response->statusCode();
echo $response->body();
print_r($response->headers());

Template in Sendgrid looks like this:

Dear -first_name- -last_name-,

Foo bar...

Kind Regards
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文