BentoSdk.Emails (BentoSDK v0.1.1)
View SourceFunctions for sending emails through Bento.
Summary
Functions
Send a single email to a subscriber. This respects subscription status - unsubscribed users won't receive the email.
Send multiple emails in a single batch.
Send a transactional email to a subscriber. This will always send, even if the user is unsubscribed.
Validates that an email address is properly formatted. Raises an ArgumentError if the email is invalid.
Functions
Send a single email to a subscriber. This respects subscription status - unsubscribed users won't receive the email.
Parameters
to
- The email address of the recipientfrom
- The email address of the sender (must be an author in your account)subject
- The subject of the emailhtml_body
- The HTML body of the emailpersonalizations
- Key-value pairs of custom data to be injected into the email
Examples
BentoSdk.Emails.send(
"user@example.com",
"noreply@yourdomain.com",
"Welcome to our service",
"<h1>Welcome!</h1><p>Thanks for signing up.</p>",
%{
"first_name" => "John"
}
)
{:ok, %{
"results" => 1
}}
Send multiple emails in a single batch.
Parameters
emails
- A list of email maps, each with the following keys:to
- The email address of the recipientfrom
- The email address of the sendersubject
- The subject of the emailhtml_body
- The HTML body of the emailpersonalizations
- Key-value pairs of custom data (optional)transactional
- Whether this is a transactional email (optional)
Examples
BentoSdk.Emails.send_bulk([
%{
to: "user1@example.com",
from: "noreply@yourdomain.com",
subject: "Welcome to our service",
html_body: "<h1>Welcome!</h1><p>Thanks for signing up.</p>",
personalizations: %{"first_name" => "John"}
},
%{
to: "user2@example.com",
from: "noreply@yourdomain.com",
subject: "Your order has shipped",
html_body: "<h1>Order Shipped</h1><p>Your order #123 has shipped.</p>",
personalizations: %{"first_name" => "Jane", "order_number" => "123"},
transactional: true
}
])
{:ok, %{
"results" => 2
}}
Send a transactional email to a subscriber. This will always send, even if the user is unsubscribed.
Parameters
to
- The email address of the recipientfrom
- The email address of the sender (must be an author in your account)subject
- The subject of the emailhtml_body
- The HTML body of the emailpersonalizations
- Key-value pairs of custom data to be injected into the email
Examples
BentoSdk.Emails.send_transactional(
"user@example.com",
"noreply@yourdomain.com",
"Your order has shipped",
"<h1>Order Shipped</h1><p>Your order #123 has shipped.</p>",
%{
"first_name" => "John",
"order_number" => "123"
}
)
{:ok, %{
"results" => 1
}}
Validates that an email address is properly formatted. Raises an ArgumentError if the email is invalid.
Parameters
email
- The email address to validate
Examples
BentoSdk.Emails.validate_email("user@example.com")
:ok
BentoSdk.Emails.validate_email("invalid-email")
** (ArgumentError) Invalid email format