Given that we have access to the transactional email scope, how can we use the API to send HTML/text emails without templates?
import time
from hubspot import HubSpot
from hubspot.marketing.transactional import PublicSingleSendRequestEgg
api_client = HubSpot(access_token='ABC')
message = {
"from": "sender@origin.com",
"to": "user@example.com"
}
public_single_send_request_egg = PublicSingleSendRequestEgg(email_id=int(time.time()), message=message)
api_client.marketing.transactional.single_send_api.send_email(public_single_send_request_egg=public_single_send_request_egg)
Where do we provide the email subject and email body (HTML or text)? Since the body content change constantly, it is impossible to create pre-defined templates.
Hi @MDrapeau
Looks your code is missing a crucial element for sending emails with dynamic content - the actual body content (HTML or text)
Here is a sample.
message = {
**"from": "sender@origin.com",**
**"to": "user@example.com",**
**"subject": "Your Dynamic Email Subject", # Update with your subject line**
**"html": "\<h1>This is the HTML content of your email.\</h1>" # Update with your HTML content**
**# OR**
**"text": "This is the plain text content of your email." # Update with your plain text content (optional)**
}
Hope this helps - Happy to help further!!
Thank you very much and have a great one!
Warm regards
Creating a “skeleton” in the UI without a subject is not possible.
Also, html does not seem to be added in the body of emails being sent.
How to bypass this limitation?
If you’re just looking to send simple, transactional-style emails via the HubSpot API, the most straightforward option is using the Single-send API with a regular email template. It’s not designed for bulk or marketing emails, but it works well for basic messages like confirmations or follow-ups. You’ll need to create and publish the email in HubSpot first, then trigger it using the API with the contact’s email and any personalization tokens. Just make sure the email is marked as “for automation” so it can be used this way.