Email Marketing Tool

Sugapriya9293
Member

How do I send a transactional email to a contact list in one-go from middleware?

SOLVE

I do not want to loop through every contact email on a list to send transactional email to a list programmatically. Is there any other way I can send transactional email or any hubSpot email service programmatically to a list of users in one-go? I already have the contact list in my account. I just want to send an email to all of them without looping through each contact.

0 Upvotes
1 Accepted solution
himanshurauthan
Solution
Thought Leader | Elite Partner
Thought Leader | Elite Partner

How do I send a transactional email to a contact list in one-go from middleware?

SOLVE

 

I apologize for the confusion. The endpoint I specified in the code is not correct. The correct endpoint for sending transactional emails using the HubSpot Email API is:

 

The message. to property can only accept a single recipient email address, as you mentioned. If you want to send an email to multiple recipients, you will need to make multiple API requests, one for each recipient.

As for passing custom properties, the HubSpot Email API does not support passing custom properties in the API request. However, you can include merge fields in your email template and use the values passed in the API request to populate the merge fields in the final email that is sent to the recipient.

I hope this clarifies your concerns.

Digital Marketing & Inbound Expert In Growth Hacking Technology

View solution in original post

3 Replies 3
himanshurauthan
Thought Leader | Elite Partner
Thought Leader | Elite Partner

How do I send a transactional email to a contact list in one-go from middleware?

SOLVE

Hello @Sugapriya9293 

you can send a transactional email to a list of contacts programmatically in one-go using the HubSpot Email API. The API allows you to send an email to a list of contacts using a single API request, rather than having to loop through each contact and send a separate email. To use the API, you will need to create an email template in HubSpot and then make a POST request to the API with the template ID and a list of recipient email addresses.

Here is an example in Python:



import requests

api_key = "your-api-key"
template_id = "your-email-template-id"
recipient_list = ["recipient1@example.com", "recipient2@example.com", ... ]

url = f"https://api.hubapi.com/email/public/v1/singleEmail/send?hapikey={api_key}"

payload = {
    "templateId": template_id,
    "recipientEmails": recipient_list,
    "message": {
        "subject": "Your subject line",
        "from": {
            "email": "sender@example.com",
            "name": "Sender name"
        }
    }
}

response = requests.post(url, json=payload)

if response.status_code == 202:
    print("Email sent successfully")
else:
    print("Error sending email")

You will need to replace your-api-key and your-email-template-id with your own values, and populate the recipient_list with the email addresses of the recipients you want to send the email to.

Digital Marketing & Inbound Expert In Growth Hacking Technology
Sugapriya9293
Member

How do I send a transactional email to a contact list in one-go from middleware?

SOLVE

Hi Himanshu,

I cannot find the related API documentation. I just found this : https://developers.hubspot.com/docs/api/marketing/transactional-emails#endpoint?spec=POST-/marketing.... It has message.to where i can pass single email id and not a list. Can you please share the related API documentation to the v1 URL you specified? I would also like to pass custom properties to the request which will be used in email template body. Does this v1 end point support passing custom properties too?

0 Upvotes
himanshurauthan
Solution
Thought Leader | Elite Partner
Thought Leader | Elite Partner

How do I send a transactional email to a contact list in one-go from middleware?

SOLVE

 

I apologize for the confusion. The endpoint I specified in the code is not correct. The correct endpoint for sending transactional emails using the HubSpot Email API is:

 

The message. to property can only accept a single recipient email address, as you mentioned. If you want to send an email to multiple recipients, you will need to make multiple API requests, one for each recipient.

As for passing custom properties, the HubSpot Email API does not support passing custom properties in the API request. However, you can include merge fields in your email template and use the values passed in the API request to populate the merge fields in the final email that is sent to the recipient.

I hope this clarifies your concerns.

Digital Marketing & Inbound Expert In Growth Hacking Technology