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 ?
To create your templates, navigate to the SendGrid Dashboard, click Email API and then Dynamic templates on the left menu. In the Dynamic Templates screen, click the "Create a Dynamic" template button.
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
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With