Wraps the HubSpot Single Send API https://developers.hubspot.com/docs/methods/email/transactional_email.
Documentation for the Single Send API can be found here: https://developers.hubspot.com/docs/methods/email/transactional_email/single-send-overview
gem install hubspot-mailer
Or with bundler,
gem "hubspot-mailer"
Before using the library, you must initialize it with your HubSpot API key. If you're using Rails, put this code in an initializer:
Hubspot.configure(hapikey: "YOUR_API_KEY")
If you have a HubSpot account, you can get your api key by logging in and visiting this url: https://app.hubspot.com/keys/get
The usage is the same as for ActionMailer with that difference there is no way to add attachments and a set of additional params.
class ApplicationMailer < Hubspot::Mailer
default from: "[email protected]"
def test_mail
mail(
to: "[email protected]",
subject: "Test Email",
email_id: 123,
send_id: SecureRandom.hex(8)
contact_properties: { first_name: "John", last_name: "Doe" },
custom_properties: { property: "Value" }
)
end
end
The content ID for the transactional email, which can be found in Email Tool UI.
The ID of a particular send. No more than one email with a given sendId will be send per portal, so including a sendId is a good way to prevent duplicate email sends.
Each property will get set on the contact record and will be visible in the template under {{ contact.NAME }}.
Each property will be visible in the template under {{ custom.NAME }}.
Add this line to config/environments/test.rb
:
Hubspot::Mailer.delivery_method = :test
Now you can use the same ActionMailer::Base.deliveries
to read sent emails in your tests.