What Is a Transactional Email?

What Is Transactional Mailing and How It Works?
Valeriia Dziubenko Valeriia Dziubenko 07 december 2021, 13:58 502
For beginners

What is a transactional email? You already know the answer. Your inbox probably has plenty of these! Transactional emails are the ones that are used to verify your accounts or confirm your orders. Everyone receives them from time to time. In this article, we will tell you how such messages work and how they are created.

Example of a transactional email message

A Bit of Terminology

The term ‘transactional emails’ is used to denote notification letters sent automatically when a certain event (usually called ‘trigger’) takes place:

  • newsletter subscription;
  • activation of an account;
  • purchase on a website, etc.

Just think of typical e-commerce transactions accompanied by the corresponding newsletters, such as abandoned cart reminders.

Transactional messages have certain differential characteristics:

  1. They are timely. Usually recipients are waiting for these messages. They know that the letter is about to come and refresh their inbox until it arrives.
  2. They contain valuable information. It may be the user’s login, shipping information, or order details – in any case, the information relates to the recipient’s recent activity and is therefore essential for him.
  3. They are created dynamically and sent through an automated workflow procedure.
Notification letter sent automatically after newsletter subscription

Discussing the definition of transactional emails, we should keep in mind the following: the core difference between these messages and promotional ones is that the former are triggered by certain events or interactions, while the latter are integrated into the company’s marketing strategy. Promotional letters do not require any particular trigger to be sent.

Besides, people do not have to opt-in to transactional messages. They receive them as soon as they have performed certain actions – placed an order, added items to the shopping cart, etc. For marketing campaigns, businesses must obtain the user’s permission for sending their newsletters. And once they have this, they should give subscribers the opportunity to opt out if they do not want to receive promotional emails anymore.

What Is Transactional Email Used for?

People use transactional email service for the following purposes:

  1. Receipts and confirmations
  2. The letters of this kind are sent after a transaction has taken place. The recipient receives a message containing information about the purchase he has just made online, an order confirmation and a payment receipt. Also, confirmation messages may relate to user sign-up or registration.

    Confirmation email message
  3. Requests
  4. When a website visitor or app user submits a support request, he receives a transactional email with the corresponding information. As a rule, these messages are urgent and contain only the answer to the recipient’s question. A good example of an explicit request is lost password recovery. The user cannot access his account without his password; therefore, the letter must come immediately after the request has been submitted.

    Password recovery email
  5. Account-related notifications
  6. They are triggered by changes in users’ accounts, such as long overdue bills or unsuccessful payment attempts. Dunning emails are a type of account-related notification, too. They keep customers informed of everything happening with their accounts, payments, orders, and more. Without these sort of transactional emails, people may not be aware of certain problems with their accounts.

    Dunning emails
  7. Behavioral alerts
  8. Messages of this kind are sent when a user has interacted with a particular element of the company’s site or app. Being more marketing-focused than other types of transactional emails, they are aimed at increasing customer loyalty. Onboarding letters, abandoned cart messages, and reactivations are examples of behavioral emails. Their purpose is to remind subscribers of the company and engage them in further interaction.

    Behavioral alerts
  9. Referrals and invitation letters
  10. Many companies offer their clients the chance to invite their friends and acquaintances by sending referrals and invitations. As a rule, messages of this kind offer certain bonuses for the recipients: if they send an invitation to another user, they may receive, for example, a discount on their next purchase. Referral transactional messages can also offer gift cards, small presents added to an order, or free services.

    Referral transactional messages
  11. Event-driven notifications
  12. Just what it sounds like – these messages relate to certain events. They are similar to mobile phone push notifications that inform subscribers about changes in their accounts, payments, orders, and more. Event-driven notifications can remind customers of a package shipment or forthcoming meetings. Unlike behavioral emails, they are connected with the company’s service or other people’s activity, but not with the recipient’s actions.

    Event-driven notifications
  13. Digests
  14. Summaries and digests inform subscribers of a wide range of events that have taken place during a given time period. They may include a list of comments, new articles on the website, or goods offered by the company. Digests are sent at fixed intervals – daily, weekly, or monthly depending on the company’s intentions. Newsletters of this kind are useful for those who want to keep track of events without having to constantly check their inbox.

    Summaries and digests
  15. Feedback requests

The definition of transactional emails of this type is obvious: they allow businesses to receive customer feedback. If a client submits a request but does not get a receipt report, he may be confused. The sooner he gets the letter confirming that his request is being processed, the better. Like onboarding emails, feedback messages can be sent when a client has made a purchase or signed up for an account – they ask users to leave their feedback on certain products, businesses, or services.

Feedback requests

How to Create Transactional Messages

If you see that your business requires these kinds of newsletters, follow the plan below:

  • Set a transactional email marketing strategy

First, you need to identify the content of your messages. Their major purpose is to increase engagement with your audience; therefore, the newsletters should be relevant, useful, and helpful for subscribers.

Then, select the most suitable email templates according to your customers’ interests and needs. Typically, transactional messages are sent via API or SMTP. Ask your developers to set up a system that sends such messages to certain recipients after a given number of actions.

  • Learn transactional email logistics

To succeed in your campaign, you will require some testing: try sending different messages and find out which of them are most efficient. Here are some nuances that can make your communications more engaging:

  1. Be well-timed. Send your emails as soon as possible. Most probably, the recipient is waiting for your message, as he has performed certain actions – left a request, placed an order, or whatever.
  2. Be brief. The purpose of transactional means is to provide important data at the user’s request. Thus, you should be brief and stick to the point. Do not take up a lot of your reader’s time. Have a clear call to action, if necessary, but avoid imagery and unnecessary details.

Test your messages.

Try using different subject lines – they are ideal for A/B testing. Send two groups of newsletters and check which one works better. The content of the emails should be the same, so as not to affect the results of the test. After that, you can test other elements of your emails in the same way.If your transactional email marketing is too pushy, it may annoy your subscribers and even violate existing anti-spam laws. Therefore, you should try your best to make your messages timely and helpful, yet not too frequent. Besides, you must remember the following rules:

Testing transactional email
  • Stay compliant

If your transactional email marketing is too pushy, it may annoy your subscribers and even violate existing anti-spam laws. Therefore, you should try your best to make your messages timely and helpful, yet not too frequent. Besides, you must remember the following rules:

  1. Do not use misleading headers. Specify your company name, domain, and email address in the most accurate way.
  2. Do not use dissembling subject lines. State the topic of the letter without any misleading phrases.Specify your company’s postal address in the email. The recipients have the right to know where you are located.
  3. Specify your company’s postal address in the email. The recipients have the right to know where you are located.
  4. Let your subscribers opt out of receiving future emails. Make sure the corresponding button or link is clear and identifiable.

That is all you need to know about transactional email marketing, how it works and how to create it. Use this information to deepen your relationship with your customers and subscribers by providing rapid, targeted, and useful responses to their requests.

Related Articles

Blog
For beginners
How to Send an Email with Python

Email notifications are essential for every business with an online presence. Over 4 billion active email users worldwide make it the best medium to reach customers. You can remind customers about important upcoming events, verify password changes, notify of login attempts, etc. Businesses use email to inform their customers of upcoming discounts and promotions to get higher sales.

Apart from sending emails manually, you may use programming languages like Python. This article will show how to implement the latter option. We’ll explain how sending emails via Python works and give you some good examples.

What email sending options do you have with Python?

The Simple Mail Transfer Protocol (SMTP) powers the massive flow of information exchange between email servers worldwide. Python supports the use of SMTP with a built-in smtplib module as part of its standard library. This module makes it easy to send emails via SMTP connections; it implements the standard RFC 821 (SMTP) and RFC 1869 (ESMTP) specifications and needs no extra installations to work.

You can use the smtplib module to automate sending transactional and bulk emails. It does not limit you to plain-text emails: you may also compose HTML messages and add attachments such as photos, PDF documents, etc.

Send emails via a third-party email service provider using API

From a programmer’s viewpoint, there’s hardly any difference between using your own SMTP server or the one provided by another party, be it your company’s IT department or an external service. However, operating your own SMTP servers makes you responsible for maintaining and securing them, which can be cumbersome and disruptive to your core business. Instead, you can choose an external email service provider (ESP) like UniOne to handle the task and make your life easier.

It should be noted that a good ESP usually offers two different ways to send emails. The most basic one is an SMTP API, which can be accessed using the same smtplib module mentioned above. The only difference is that you’ll need to specify the external server’s hostname and port instead of your own.

The second option is to use a specialized application programming interface, or API. This method does not rely on smtplib; instead, it uses the HTTP protocol to send commands to the ESP’s server. This method offers numerous advantages over the first one, but requires more complex programming.

In this article, we’ll show you the most essential examples using the smtplib module and Python on Windows. The same code will also work on Linux machines, but may require some fixes. If you need information about using the HTTP API, refer to the ESP’s documentation.

A step-by-step guide to sending emails with Python

How to send emails using a local SMTP server

A local SMTP server is a server that resides on your system. Typically you don't use it to send actual emails, but it will come handy if you need to check whether your Python script works correctly. You may install any popular server that is available for your OS. However, the easiest approach will be using an smtpd module that comes bundled with Python on Windows. Actually, it does not send your emails anywhere; it just outputs the message to your console, which is all you need for debugging.

To start smtpd, enter the following command at your command prompt:

python -m smtpd -c DebuggingServer -n localhost:2501

Now you have an instance of smtpd listening on port 2501. Let’s proceed with actual coding. Below is the most basic Python script to send an email from a local SMTP server:

import smtplib

sender = 'from@example.com'
receivers = ['to@example.com']
message = """From: Sender <from@example.com>
To: Addressee <to@example.com>
Subject: Test message #1


This is a test message for this UniOne tutorial on sending emails with Python.
"""

try:
    smtpObj = smtplib.SMTP('localhost', 2501)
    smtpObj.setdebuglevel(1)
    smtpObj.sendmail(sender, receivers, message)
    smtpObj.quit()      
    print("Successfully sent an email")
except SMTPException:
    print("Something has gone wrong")

Let’s take a closer look at the code. The first step is to import the smtplib module:

 

import smtplib

 

To send emails, we create an SMTP object:

 

smtpObj = smtplib.SMTP([host [, port]])

 

Provide the correct values for the above parameters:

  • host - This part refers to the hostname of your SMTP server. Use localhost as a host name if the server runs on your local machine.
  • port - Specifies the port number to use. It will be your local SMTP port number, or the one you’ve specified on the smtpd command line.

Now we have an open SMTP connection to the server, and may proceed with sending a simple email message. For this, the SMTP object has an instance method called sendmail(). This method requires three parameters:

  • sender − a string with the sender’s From address
  • receivers − a list of strings, one for each recipient’s address
  • message − a message formatted as specified in RFCs (note the two empty lines separating the headers section from the body)

Before calling this method, we enable the debugging mode for our SMTP object to see what’s happening when the script is run.

The next line checks whether an error has occurred while connecting to the server or sending a message. SMTPException is the base exception class for smtplib; for more sophisticated error processing, consult the module’s documentation.

Using an external SMTP server

The above example assumes you’re running an SMTP server locally on your PC. If not, you’ll need to modify the script accordingly, as described below.

When sending emails via SMTP, you’ll also want to encrypt the connection. Unencrypted connections can be intercepted by hackers looking to steal sensitive information. Encrypting prevents this problem.

For an encrypted connection, you’ll need this code to create an SMTP object:

smtpObj = smtpObj.SMTP_SSL(host, port)

This object is identical to smtplib.SMTP, but uses an implicit SSL connection to the server. For the host parameter, you specify your server's IP address or domain name. The port value defaults to 465, the standard for SMTP over SSL. For more information on secure connections, see our blog article.

When connecting to an external server, you’ll also need to properly introduce yourself. For this, the following method call is used:

smtpObj.login(username, password)

In the examples below, we’ll use one of the SMTP servers provided by UniOne. Connecting to our SMTP server is simple; you just need to use the proper connection parameters:

  • host: either smtp.us1.unione.io or smtp.eu1.unione.io (for accounts registered at us1.unione.io and eu1.unione.io, respectively).
  • port: 25, 465 or 587. You can use any of these ports; all our connections are encrypted by default, so you don't need to worry about that.
  • username: your account’s user_id or project_id (you can look up these parameters in your UniOne dashboard).
  • password: your account's API key or project_api_key.
  • encoding: use UTF-8.

For more things to note when using UniOne, see info on our SMTP API.

This is how the code will finally look like:

import smtplib

port = 465 
smtp_server = "smtp.us1.unione.io"
login = "123456789" # your UniOne user_id or project_id
password = "*******" # your UniOne API key or project_api_key

sender_email = "UniOne@example.com"
receiver_email = "recipient@example.com"
message = """From: Sender <from@example.com>
To: Addressee <to@example.com>
Subject: Test message #2


This is a test message sent from UniOne with Python using a secure connection.
"""

try:
    smtpObj = smtplib.SMTP_SSL(smtp_server, port)
    smtpObj.login(username, password)
    smtpObj.sendmail(sender, receivers, message) 
    smtpObj.quit()        
    print("Successfully sent an email")
except SMTPException:
    print("Something has gone wrong")

How to send HTML emails with Python

In the next example, we'll use the MIME message type that combines HTML/CSS and plain text. In Python, MIME messages are handled by the email.mime module.

It's advisable to write separate text and HTML versions of your email and merge them with the MIMEMultipart("alternative") Python object instance. This approach means that an email client can render your message in either HTML or text.

# Import the necessary components
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

port = 587 
smtp_server = "smtp.us1.unione.io"
login = "123456789" # your UniOne user_id or project_id
password = "*******" # your UniOne API key or project_api_key

sender_email = "UniOne@example.com"
receiver_email = "recipient@example.com"
message = MIMEMultipart("alternative")
message["Subject"] = "Multipart email test"
message["From"] = sender_email
message["To"] = receiver_email

# the plain text part
text = """\
Hi,
Check out our new post on the UniOne blog about sending emails with Python:
We hope you learn a lot from it"""

# the HTML part
html = """\
<html>
  <body>
    <p>Hi,<br>
      Check out our new post on the UniOne blog about sending emails with Python.</p>
    <p>We hope you learn a lot from it.</p>
  </body>
</html>
"""

# convert both parts to MIMEText objects and add them to the MIMEMultipart message
part1 = MIMEText(text, "plain")
part2 = MIMEText(html, "html")
message.attach(part1)
message.attach(part2)

# send your email
with smtplib.SMTP_SSL(smtp_server, port) as server:
    server.login(login, password)
    server.sendmail(
        sender_email, receiver_email, message.as_string()
    )

print('Message sent')

How to send emails with attachments

The next thing to learn is how to send emails with attachments using Python.

Python lets you attach text files, documents, images, videos, audio, etc. You just need to use the proper email class, such as email.mime.image.MIMEImage or email.mime.text.MIMEtext.

Keep in mind that the maximum total size for a UniOne email, including text and all attachments, is 10 MB.

import smtplib

# import the required modules
from email import encoders
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

port = 587 
smtp_server = "smtp.us1.unione.io"
login = "123456789" # your UniOne user_id
password = "*******" # your UniOne API key or project_api_key

subject = "How to send emails using Python"
sender_email = "UniOne@example.com"
receiver_email = "recipient@example.com"

message = MIMEMultipart()
message["From"] = sender_email
message["To"] = receiver_email
message["Subject"] = subject

# Add body to email
body = "This is a tutorial for sending attachments via Python"
message.attach(MIMEText(body, "plain"))

# Open PDF file in binary mode
filename = "PythonTutorial.pdf"
with open(filename, "rb") as attachment:
    # Create an attachment from your PDF file
    part = MIMEApplication(attachment.read())
    attachment.close()

# Add attachment to your message and convert it to string
part['Content-Disposition'] = 'attachment; filename="%s"' % filename
message.attach(part)
text = message.as_string()

# send your email
with smtplib.SMTP_SSL(smtp_server, port) as server:
    server.login(login, password)
    server.sendmail(
        sender_email, receiver_email, text
    )
print('Sent')

Sending emails to multiple recipients with Python

You can send emails to multiple recipients using Python code via the UniOne API. As mentioned earlier, each recipient will receive separate email copies that will count toward your subscription.

Adding more recipients is simple; just type their address separated by commas and add CC and BCC. However, this method can be stressful if you're sending messages to thousands of addresses (you likely can’t type them all). The alternative is to place all the addresses in a CSV file and point the SMTP server to that database to fetch all them.

Input:

import csv, smtplib

port = 587 
smtp_server = "smtp.us1.unione.io"
login = "123456789" # your UniOne user_id
password = "*******" # your UniOne API key or project_api_key
sender = "UniOne@example.com"
message = """Subject: Read our tutorial for sending emails via Python
To: {recipient}
From: {sender}

Hi {name}, we have written a detailed tutorial for sending emails via Python"""

with smtplib.SMTP_SSL(smtp_server, port) as server:
    server.login(login, password)
    with open("contacts.csv") as file:
        reader = csv.reader(file)
        next(reader)  # skip the header row
        for name, email in reader:
            server.sendmail(
                sender,
                email,
                message.format(name=name, recipient=email, sender=sender)
            )
            print(f'Sent to {name}')

For the above example, we have created a CSV file named “contacts.csv” with all the recipients’ names and addresses (put this file in the same folder as your Python script). This program instructs the server to read the file, fetch the email addresses, and send the email to each one.

Sending emails with images

You can send images by adding them as attachments to your emails with Python code. The best option is to add the image as a CID attachment (embedded it as a MIME object).

Input:

# import all necessary components
import smtplib
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart

port = 587 
smtp_server = "smtp.us1.unione.io"
login = "123456789" # your UniOne user_id
password = "*******" # your UniOne API key or project_api_key

sender_email = "UniOne@example.com"
receiver_email = "recipient@example.com"
message = MIMEMultipart("alternative")
message["Subject"] = "CID image testing"
message["From"] = sender_email
message["To"] = receiver_email

# write the HTML part
html = """\
<html>
 <body>
   <img src="cid:UniOneImage">
 </body>
</html>
"""

part = MIMEText(html, "html")
message.attach(part)

# This code assumes that you saved the image file in the same directory as your Python script
fp = open('UniOneImage.jpg', 'rb')
image = MIMEImage(fp.read())
fp.close()

# Specify the ID according to the img src in the HTML part
image.add_header('Content-ID', '<UniOneImage>')
message.attach(image)

# send your email
with smtplib.SMTP_SSL(smtp_server, port) as server:
    server.login(login, password)
    server.sendmail(
        sender_email, receiver_email, message.as_string()
    )
print('Sent OK')

The above code illustrates attaching an image named “UniOneImage.jpg” that you’ve already saved in the same directory as your Python script. The program instructs the SMTP server to fetch and send the image to the recipients.

Conclusion

We have explained how to write Python scripts to send plain text emails, emails having attachments, and emails with multiple recipients. By following our tips, you can send messages easily via the UniOne SMTP API.

UniOne is a secure and reliable email service that guarantees high deliverability rates if you adhere to email regulations and best practices.

Valeriia Dziubenko
05 march 2024, 16:0413 min
Blog
For beginners
Best Review Request Email Examples And Free Templates
Online customer reviews are important to every business owner. The more positive reviews you get, the more people patronize your business. Alas, most customers won’t bother leaving a review unless asked, so knowing the right way to ask is vital. This article will show you how to request a review via email and offer some examples to follow.
Denys Romanov
15 march 2024, 12:2415 min
Blog
For beginners
How to Build Your Own Email List
Create a mailing list for effective email marketing.
Vitalii Poddubnyi
21 october 2021, 12:235 min