Recipient detail in SendGrid Dynamic Template - sendgrid

I need to send a payload to multiple recipients in SendGrid. I use the Dynamic Templates to construct the email body, and all is working fine.
I would like to add a 'Hi {{recipientName}}' line to the email but I cannot find any documentation on it, is it possible?
I cannot include the recipient detail in the payload as a single payload goes out to many recipients

Use personalizations.
Personalizations allow you to override these various metadata for each email in an API request.
Your request will look like this:
{
"from": "gilbert#techmail.com",
"template_id": "YOUR TEMPLATE ID",
"personalizations": [
{
"to": [
{
"email": "john#example.com"
}
],
"substitutions": {
"%fname%": "John",
"%CustomerID%": "C001"
},
},
{
"to": [
{
"email": "peter#example.com"
}
],
"substitutions": {
"%fname%": "Peter",
"%CustomerID%": "C005"
},
"send_at": 1629723541
}
]
}
and it will go as a single request.
Also look at this github comment.

Related

SendGrid v3 Api dynamic template_id not recognised, won't send

I am trying to send a simple password reset email that's defined in a dynamic template. I have tested the template within SendGrid and it works fine. I have copied and pasted the template_id from the website, checked and double-checked it, but trying to post this message:
{
"personalizations": [
{
"to": [
{
"email": "chairman###########.org.uk"
}
],
"dynamic_template_data": {
"firstname": "Tim",
"url": "https://localhost:5001/account/ProcessPasswordReset?id=4&code=############"
},
"send_at": 0
}
],
"from": {
"email": "membership###########.org.uk",
"name": "A Person"
},
"reply_to_list": [],
"subject": "Password Reset",
"content": [],
"template_id": "d-23a2c68a9e5349488be23299a04a9485",
"send_at": 0
}
I get the following response
{
"errors": [
{
"message": "Unless a valid template_id is provided, the content parameter is required. There must be at least one defined content block. We typically suggest both text/plain and text/html blocks are included, but only one block is required.",
"field": "content",
"help": "http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.content"
}
]
}
As far as I can tell from the documentation, this is a well-formed message with a correct template_id.
Ok so the problem was the empty
"content": [],
This must not be sent at all if there is no content to send. Working as expected now this is removed.

Sending emails with SendGrid from a logic app to multiple recipients

Is there a simple way to send emails from an Azure logic app using SendGrid to multiple recipients, e.g. comma-separated etc?
This is how it looks now:
"actions": {
"Send_email_(V3)": {
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "#parameters('$connections')['sendgrid']['connectionId']"
}
},
"method": "post",
"body": {
"from": "webserver#hotmail.com",
"to": "firstaddress#somemail.com",
"subject": "** My subject **",
"text": "Some text",
"ishtml": ""
},
"path": "/v3/mail/send"
},
Is it possible to have
"to": "firstaddress#somemail.com, secondaddress#somemail.com"
?
The SendGrid V3 connector documentation states that you can separate the email addresses by comma in the To, CC or BCC fields:
Valid email addresses separated by a semicolon or comma
Checkout the documentation: SendGrid Connector

Facebook Workplace Account Management API - Update user

I have a workplace application,
I wish to change emailIds of the user via API,
I found that Account Management API
can be used to modify user details via API calls.
My use-case is to modify user email via the Account Management API, which comes under urn:scim:schemas:core:1.0 schema extension,
I wish to overwrite the existing email with the one I would specify in the requestBody,
From the documentation, I've come up with the following request -
Url endpoint -
https://someCompanyName.facebook.com/scim/v1/Users/ HTTP/1.1
Method type -
POST
Request body-
{
"schemas": [
"urn:scim:schemas:core:1.0",
"urn:scim:schemas:extension:facebook:auth_method:1.0"
],
"userName": "abc",
"name": {
"formatted": "Julius Caesar"
},
"emails": ["abc#gmail.com"],
"urn:scim:schemas:extension:facebook:auth_method:1.0": {
"auth_method": "password"
}
}
Is it correct? What modifications do I need to make to the request?
in order to change the emails of a user you have to do a PUT request to the address https://www.facebook.com/scim/v1/Users/{userId}
and you have to change in your payload the email address:
{
"schemas": [
"urn:scim:schemas:core:1.0",
"urn:scim:schemas:extension:facebook:auth_method:1.0"
],
"userName": "abc",
"name": {
"formatted": "Julius Caesar"
},
"emails": [
{
"primary": true,
"type": "work",
"value": "newemail#gmail.com"
}
],
"urn:scim:schemas:extension:facebook:auth_method:1.0": {
"auth_method": "password"
}
}
Hope it helps

Mandrill sending to multiple people as separate message via the REST API

I'm trying to send out mails using mandrill. The problem is that when I add multiple recipients to the 'to' parameter, it sends out the same mail multiple times with ALL the recepients in the 'to' list. I was expecting the same mail to be sent out individually to every person in the to list. Am I missing something ?
{
"key": "app-key",
"template_name": "platform-invite",
"template_content": [
{
"name": "connection",
"content": "<a class=\"mcnButton \" title=\"Lets Go\" href=\"http://someurl\" target=\"_blank\" style=\"font-weight: normal;letter-spacing: normal;line-height: 100%;text-align: center;text-decoration: none;color: #FFFFFF;\">Lets go</a>"
},
{
"name": "mailbody",
"content": "<p>Hi </p>\n<p>I would like you to be a ... Tic tic tic...</p>"
}
],
"message": {
"subject": "My subject line over herer",
"from_email": "superman#mydomain.co",
"to": [
{
"email": "person1#gmail.com,
"type": "to"
},
{
"email": "person2#gmail.com",
"type": "to"
},
{
"email": "person3#gmail.com",
"type": "to"
},
{
"email": "person4#gmail.com",
"type": "to"
}
],
"merge_vars": {}
},
"async": false,
"ip_pool": "Main Pool"
}
There's an option in your Sending Options to expose recipients to one another. You can uncheck that box to not show everyone's information in the 'to' header. The option(s) you select in the Sending Options are used by default for your account. You can override any of these options in individual API calls. In this case, you could use the preserve_recipients parameter to override the current default that's set for your account.

Defining X-SMTPAPI header

Question 1: Do I need to strictly follow the order while defining the X-SMTPAPI
header related order mentioned in the doc ?
The doc(http://sendgrid.com/docs/API_Reference/SMTP_API/) mentions it like this:
{
"to": [
"ben#sendgrid.com",
"joe#sendgrid.com"
],
"sub": {
"%name%": [
"Ben",
"Joe"
],
"%role%": [
"%sellerSection%",
"%buyerSection%"
]
},
"section": {
"%sellerSection%": "Seller information for: %name%",
"%buyerSection%": "Buyer information for: %name%"
},
"category": "Orders",
"unique_args": {
"orderNumber": "12345",
"eventID": "6789"
},
"filters": {
"footer": {
"settings": {
"enable": 1,
"text/plain": "Thank you for your business"
}
}
}
}
So, my email header in this case would look like the following in coldfusion:
<cfset myheaderdefinition = XMLFormat('X-SMTPAPI|{
"to": [
"ben#sendgrid.com",
"joe#sendgrid.com"
],
"sub": {
"%name%": [
"Ben",
"Joe"
],
"%role%": [
"%sellerSection%",
"%buyerSection%"
]
},
"section": {
"%sellerSection%": "Seller information for: %name%",
"%buyerSection%": "Buyer information for: %name%"
},
"category": "Orders",
"unique_args": {
"orderNumber": "12345",
"eventID": "6789"
},
"filters": {
"footer": {
"settings": {
"enable": 1,
"text/plain": "Thank you for your business"
}
}
}
}
') >
Question #2: Does the way I have defined my header looks good?
More clarifications on Question #1:
1.1 Do I need to use to,sub,role,section etc in the same order as mentioned? OR can I skip one of these if I am not using these?
1.2 How would I determine what sendgrid is expecting for unique_args and other fields?
1 - 1.1 You may use any number of SMTPAPI parameters in any order you wish, in the JSON object you provide SendGrid. You may omit those you are not using. The sample provided in the SendGrid docs is only that, not a requirement.
1.2 unique_args and the rest of the parameters are fields only meant for you. SendGrid is not expecting anything. As you provide parameters SendGrid will execute on them as explained in SMTPAPI Documentation.
2 Your setup does not look right, although I am not intimately familiar with ColdFusion, it does not look as though you are correctly defining an email header. I would point toward my previous answer to your previous question as to how to set that up.
However, based on this and previous questions, I must ask, are you sure you want to use SendGrid's SMTPAPI or just use SMTP to send email to SendGrid?
The SMTPAPI provides much additional functionality to email, based upon parameters provided to it through a JSON object. However, sending through SMTP simply transports your message to SendGrid using the protocol of SMTP.
EDIT: To further check your SMTPAPI Header, you may want to use the SMTPAPI Header Validator