<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Transactional Emails with Attachment in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Transactional-Emails-with-Attachment/m-p/1041959#M76659</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I am trying to use the Transactional API for emails &lt;A href="https://api.hubspot.com/api-catalog-public/v1/apis/marketing/v3/transactional" target="_blank" rel="noopener"&gt;https://api.hubspot.com/api-catalog-public/v1/apis/marketing/v3/transactional&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This does not seem to support attaching any documents.&lt;/P&gt;&lt;P&gt;I believe if I use the SMTP API, I can then use attachments.&lt;/P&gt;&lt;P&gt;Is that correct?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;</description>
    <pubDate>Tue, 17 Sep 2024 10:04:56 GMT</pubDate>
    <dc:creator>VPapageorgiou</dc:creator>
    <dc:date>2024-09-17T10:04:56Z</dc:date>
    <item>
      <title>Transactional Emails with Attachment</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Transactional-Emails-with-Attachment/m-p/1041959#M76659</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I am trying to use the Transactional API for emails &lt;A href="https://api.hubspot.com/api-catalog-public/v1/apis/marketing/v3/transactional" target="_blank" rel="noopener"&gt;https://api.hubspot.com/api-catalog-public/v1/apis/marketing/v3/transactional&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This does not seem to support attaching any documents.&lt;/P&gt;&lt;P&gt;I believe if I use the SMTP API, I can then use attachments.&lt;/P&gt;&lt;P&gt;Is that correct?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2024 10:04:56 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Transactional-Emails-with-Attachment/m-p/1041959#M76659</guid>
      <dc:creator>VPapageorgiou</dc:creator>
      <dc:date>2024-09-17T10:04:56Z</dc:date>
    </item>
    <item>
      <title>Re: Transactional Emails with Attachment</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Transactional-Emails-with-Attachment/m-p/1042021#M76664</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/731628"&gt;@VPapageorgiou&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is correct - using the SMTP API will allow you to use attachments with your transactional emails.&lt;/P&gt;
&lt;P&gt;If it helps I wrote an &lt;A href="https://www.linkedin.com/pulse/transactional-email-hubspot-everything-you-need-know-jack-coldrick/" target="_blank" rel="noopener"&gt;article&lt;/A&gt; a while back going through this in more detail. Also, if it helps here is some &lt;A href="https://gist.github.com/jackcoldrick90/a87c7665d5959f01178bf5d30e09ea05" target="_blank" rel="noopener"&gt;sample code&lt;/A&gt; I used to attach an image to an email using SMTP API.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import requests
import urllib
import json
import smtplib
import os
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart


#1. CREATE THE TOKEN
# This function is used to create the token. This will provide us with the credentials required access our SMTP servers.
# It takes 3 arguments, who the token is created by, the name of the token and whether or not we want the token to create new contacts.
# You'll also notice an "Authorization" header. You must use oAuth in order to authenticate and generate a token via our API.
def create_smtp_api_token(created_by, campaign_name, create_contact): 
    data = json.dumps({
        "createdBy": created_by,
        "campaignName": campaign_name,
		"createContact": create_contact
    })
    r = requests.post("https://api.hubapi.com/marketing/v3/transactional/smtp-tokens" , data, headers={"content-type": "application/json", "Authorization": "Bearer {{YOUR_ACCESS_TOKEN}}"})
    if 200 &amp;lt;= r.status_code &amp;lt; 300:
        return r.json()
    else:
        raise Exception("Unknown error with HubSpot API: code:{0}, response:{1}".format(r.status_code, r.content))

#2. SET VARIABLES
# Here we define who we want to send the email from and who we wish to send the email to. We also specify additional components of the email 
# for instance the subject line and the body.
FROM_EMAIL = "{{YOUR_EMAIL_ADDRESS}}"
TO_EMAIL = "{{RECIPIENTS_EMAIL_ADDRESS}}"
SUBJECT = "SMTP API - Test Email w. attachment"
MESSAGE = "This is a test email send using HubSpots SMTP API. You'll notice it includes an attachment"


#3. SEND EMAIL
# This function takes the SMTP token we generated and connects to the HubSpot SMTP server to trigger the send of the email.
# notice how we use the variables above to specify the subject and the body of the email itself.
def send_test_email(smtp_api_token):

	
    img_data = open("hubspot.png", 'rb').read()
	
    server = smtplib.SMTP("smtp.hubapi.com", 587)
	
    server.starttls()
    server.login(smtp_api_token['id'], smtp_api_token['password'])
	
    msg = MIMEMultipart()
    msg['Subject'] = SUBJECT
    msg['From'] = FROM_EMAIL
    msg['To'] = TO_EMAIL
    text = MIMEText(MESSAGE)
    msg.attach(text)
    image = MIMEImage(img_data, name=os.path.basename("hubspot.png"))
    msg.attach(image)
	
    server.sendmail(FROM_EMAIL, TO_EMAIL, msg.as_string())
    server.quit()
	
    print ("Enqueued email")
	
#4. CALL THE FUNCTIONS
smtp_api_token = create_smtp_api_token("{{YOUR_NAME}}", "{{TOKEN_NAME}}", "true") #Generate token and save in a variable
send_test_email(smtp_api_token) #Send email using the token we just generated&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps!&lt;/P&gt;
&lt;P&gt;Jack&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2024 12:12:40 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Transactional-Emails-with-Attachment/m-p/1042021#M76664</guid>
      <dc:creator>coldrickjack</dc:creator>
      <dc:date>2024-09-17T12:12:40Z</dc:date>
    </item>
  </channel>
</rss>

