Getting started with MailerSend
Step 1: Sign up for a free MailerSend account
1. Create your free MailerSend account.
2. Confirm your email address from the verification email sent to the address you signed up with.
Your account will now be activated with a trial plan and you can send an email with your trial domain.
Step 2: Create an API token or SMTP user
To send email with the API, from the dashboard:
1. Click the API option.
2. Enter a name and expiration date for your API token and select the permissions.
3. Click Generate token.
4. Save or download your API token. You won't be able to access it again for security reasons.
To send an email with the SMTP relay, from the dashboard:
1. Click the SMTP relay option.
2. Enter a name for your SMTP user.
3. Click Save user.
4. Your SMTP credentials will be generated. Copy or download your password, you won't be able to access it again.
Step 3: Send an email
1. Install the SDK for your preferred language:
composer require mailersend/mailersend
composer require mailersend/laravel-driver
<dependency>
<groupId>com.mailersend</groupId>
<artifactId>java-sdk</artifactId>
<version>1.5.0</version>
</dependency>
npm install mailersend
go get github.com/mailersend/mailersend-go
pip install mailersend
gem install mailersend-ruby
2. Then copy and paste the code snippet into your project, adding your API token.
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;
$mailersend = new MailerSend();
$recipients = [
new Recipient('your@client.com', 'Your Client'),
];
$emailParams = (new EmailParams())
->setFrom('your@domain.com')
->setFromName('Your Name')
->setRecipients($recipients)
->setSubject('Subject')
->setHtml('This is the HTML content')
->setText('This is the text content')
->setReplyTo('reply to')
->setReplyToName('reply to name');
$mailersend->email->send($emailParams);
<?php
namespace App\Mail;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Arr;
use MailerSend\Helpers\Builder\Personalization;
use MailerSend\Helpers\Builder\Variable;
use MailerSend\LaravelDriver\MailerSendTrait;
class TestEmail extends Mailable
{
use Queueable, SerializesModels, MailerSendTrait;
public function __construct() {}
public function envelope(): Envelope
{
return new Envelope(
subject: 'Test Email',
);
}
public function content(): Content
{
$to = Arr::get($this->to, '0.address');
$this->mailersend(
template_id: null,
tags: ['tag'],
personalization: [
new Personalization($to, [
'var' => 'variable',
'number' => 123,
'object' => [
'key' => 'object-value'
],
'objectCollection' => [
['name' => 'John'],
['name' => 'Patrick']
],
])
],
precedenceBulkHeader: true,
sendAt: new Carbon('2022-01-28 11:53:20'),
);
return new Content(
view: 'emails.test_html',
text: 'emails.test_text'
);
}
public function attachments(): array
{
return [
Attachment::fromStorageDisk('public', 'example.png')
];
}
}
import com.mailersend.sdk.emails.Email;
import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.MailerSendResponse;
import com.mailersend.sdk.exceptions.MailerSendException;
public void sendEmail() {
Email email = new Email();
email.setFrom("name", "your email");
email.addRecipient("name", "your@recipient.com");
email.addRecipient("name 2", "your@recipient2.com");
Recipient recipient = new Recipient("name", "your@recipient3.com");
email.AddRecipient(recipient);
email.setSubject("Email subject");
email.setPlain("This is the text content");
email.setHtml("<p>This is the HTML content</p>");
MailerSend ms = new MailerSend();
ms.setToken("Your API token");
try {
MailerSendResponse response = ms.emails().send(email);
System.out.println(response.messageId);
} catch (MailerSendException e) {
e.printStackTrace();
}
}
import 'dotenv/config';
import { MailerSend, EmailParams, Sender, Recipient } from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
const sentFrom = new Sender("you@yourdomain.com", "Your name");
const recipients = [
new Recipient("your@client.com", "Your Client")
];
const emailParams = new EmailParams()
.setFrom(sentFrom)
.setTo(recipients)
.setReplyTo(sentFrom)
.setSubject("This is a Subject")
.setHtml("<strong>This is the HTML content</strong>")
.setText("This is the text content");
await mailerSend.email.send(emailParams);
package main
import (
"context"
"os"
"fmt"
"time"
"github.com/mailersend/mailersend-go"
)
func main() {
ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
subject := "Subject"
text := "This is the text content"
html := "<p>This is the HTML content</p>"
from := mailersend.From{
Name: "Your Name",
Email: "your@domain.com",
}
recipients := []mailersend.Recipient{
{
Name: "Your Client",
Email: "your@client.com",
},
}
sendAt := time.Now().Add(time.Minute * 5).Unix()
tags := []string{"foo", "bar"}
message := ms.Email.NewMessage()
message.SetFrom(from)
message.SetRecipients(recipients)
message.SetSubject(subject)
message.SetHTML(html)
message.SetText(text)
message.SetTags(tags)
message.SetSendAt(sendAt)
message.SetInReplyTo("client-id")
res, _ := ms.Email.Send(ctx, message)
fmt.Printf(res.Header.Get("X-Message-Id"))
}
from mailersend import MailerSendClient, EmailBuilder
ms = MailerSendClient()
email = (EmailBuilder()
.from_email("sender@domain.com", "Your Name")
.to_many([{"email": "recipient@domain.com", "name": "Recipient"}])
.subject("Hello from MailerSend!")
.html("<h1>Hello World!</h1>")
.text("Hello World!")
.build())
response = ms.emails.send(email)
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_email = Mailersend::Email.new(ms_client)
ms_email.add_recipients("email" => "ron@parksandrec.com", "name" => "Ron")
ms_email.add_recipients("email" => "leslie@parksandrec.com", "name" => "Leslie")
ms_email.add_from("email" => "april@parksandrec.com", "name" => "April")
ms_email.add_subject("Time")
ms_email.add_text("Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.")
ms_email.add_html("<b>Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.</b>")
ms_email.send
Send with SMTP
To send with SMTP, add the following to your code or app configuration:
SMTP server: smtp.mailersend.net
Port: 587 or 2525
SMTP username
SMTP password
Below are instructions for the most popular tools, packages and plugins.
Most SMTP plugins will work in the same way, so you can use whichever one you prefer. However, we recommend that you select a plugin with caution to ensure that your credentials remain secure.
While WP SMTP Mail is an SMTP plugin for WordPress, it uses an API key to configure the connection to your MailerSend account.
To use the setup wizard and your API key:
1. Go to WP SMTP Mail in the WordPress dashboard and open Settings. 2. In the General tab, click Launch Setup Wizard. 3. Click Let's Get Started and in the next window, select MailerSend then click Save and Continue. 4. Add your API key, From Name, and From Email and click Save and Continue. 5. Follow the remaining steps to complete the plugin configuration.
This is our official SMTP plugin for WordPress, and the most secure way to configure SMTP for your WordPress website.
1. Install the MailerSend SMTP Plugin by going to Plugins and searching for MailerSend. 2. Find the MailerSend - Official SMTP Integration by MailerSend plugin and install and activate it. 3. Open the plugin from the side menu and enter your SMTP username and password. Click Save.
From here, you can also configure your Sender details (name, email address, CC recipients, BCC recipients, Reply-to address, and tags, and send a test email to check that your SMTP credentials are configured correctly.
This is our official plugin for WooCommerce. You can connect your account using an API key. You can also use any other WooCommerce SMTP plugin if you prefer to use SMTP credentials.
1. Install the MailerSend WooCommerce Plugin by going to Plugins and searching for MailerSend. 2. Find the MailerSend - Transactional emails for WooCommerce by MailerSend plugin and install and activate it. 3. Open the plugin from the side menu by going to WooCommerce > MailerSend. 4. Enter your API token and click Validate token.
From here, you can also configure your Email sending options (Sender Name, Sender Address, CC Addresses, BCC Addresses) and Email notifications (templates), which you can test as well.
You can configure your Laravel app to use MailerSend SMTP relay by configuring the mailer with your SMTP credentials. First, use a basic mail command to build an email template, including the from, to, CC, BCC and content, then configure the mailer. For a standard SSL/TLS server, your configuration will look something like this:
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailersend.net
MAIL_PORT=587
MAIL_USERNAME=your_smtp_username
MAIL_PASSWORD=your_smtp_password
MAIL_ENCRYPTION=tls
1. Open FluentSMTP by going to Settings > FluentSMTP in WordPress. 2. Select Other SMTP and enter your Sender Settings (From Email and From Name). 3. Next, enter smtp.mailersend.net as the SMTP Host, and 587 as the SMTP Port. 4. Select TLS for encryption and enter your SMTP username and password. 5. Click Save Connection Settings.
You can configure PHPMailer to use MailerSend SMTP relay. Replace the SMTP credentials in the code snippet with your own to test.
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = 'smtp.mailersend.net';
$mail->SMTPAuth = true;
$mail->Username = 'your_smtp_username';
$mail->Password = 'your_smtp_password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('from@example.com', 'From Name');
$mail->addAddress('recipient@example.com', 'Recipient Name');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Your Subject Here';
$mail->Body = '<b>This is the HTML message body</b>';
if(!$mail->send()){
echo 'Message failed. Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
If you want to use SMTP to integrate email sending into your Node.js apps, you can use the Nodemailer package. The following snippet configures MailerSend's SMTP relay and sends an email (remember to add your SMTP credentials).
First, add your SMTP credentials to your project's .env file:
SMTP_HOST=smtp.mailersend.net
SMTP_PORT=587
SMTP_USER=your_mailersend_username
SMTP_PASS=your_mailersend_password
Then use the following code snippet to send the email:
import 'dotenv/config';
import nodemailer from 'nodemailer';
// Load environment variables from .env file
import dotenv from 'dotenv';
dotenv.config();
// Create a transporter object using SMTP transport
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT,
secure: false, // true for 465, false for other ports
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS,
},
});
// Setup email data
const mailOptions = {
from: '"Name" <from@example.com>', // sender address
to: 'recipient@example.com', // list of receivers
subject: 'This is a test.', // Subject line
text: 'Hey there! You just sent your first email with MailerSend. Nice one!', // plain text body
html: `
<p>Hey there!</p>
<p>You just sent your first email with MailerSend.</p>
<p>Nice one!</p>
`, // html body
};
// Send email
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message sent: %s', info.messageId);
});
Step 4: Check your email activity
Once you've sent your email, you can check your inbox to see if it's arrived as well as the Emails page.
To view the email's activity status, go to Email > Emails.
From here, you'll be able to see every point of a message's journey, from queued and sent to delivered, bounced, clicked and more.
Next steps: Take it live
Add a domain
When you're ready to start sending to recipients, the first step is to add your domain:
1. In the dashboard, scroll to the Start sending transactional emails section and click Add domain.
2. Click the Add domain button and follow the steps to authenticate your domain. With automatic domain connect, it only takes a few minutes.
Learn more:
Get approved
The account approval process is a crucial step for accessing all MailerSend features. This involves providing details about your company or organization and explaining how you plan to use MailerSend. The more information you provide, the quicker you'll gain full access to all features.
To submit your account for approval, just click Get approved from the notification in the dashboard.
The approval process is usually very quick but can take up to 48 hours. We recommend you to provide clear, detailed information in your approval requests to help speed up this process. Rest assured, we'll notify you as soon as a decision is made.
Subscribe to a Free plan
The Free plan gives you 500 emails a month free. To subscribe:
1. In the dashboard, scroll to the Start sending transactional emails section and click Choose plan.
2. Select a plan, click Upgrade and follow the steps to confirm your subscription.
Learn more:
More resources to enhance your sending
Customizing emails and templates:
Advanced sending and receiving:
| Add webhooks | → |
| Set up bulk emailing | → |
| Process incoming emails | → |
Need more info?
Feel free to reach out to support@mailersend.com. A member of our support team will gladly assist you.
- Getting started: Sending your first email
-
Email
- Add and verify a sending domain
- How to merge multiple SPF records
- Start sending transactional emails
- SMTP relay
- Testing email sending with blackhole recipients
- Email Activity
- Analytics
- Bulk email sending
- Custom headers
- Custom unsubscribe headers
- Sending domains
- Domain tracking options
- Inbound routing
- Personalization in emails
- Sender identities
- Split Testing
- Surveys
- Tagging emails
- Templates
- How to configure SMTP connections correctly (421: Service not available error)
- How to enable Google Email Actions & Highlights
- How transactional emails work
- The difference between transactional emails and marketing emails
- SMS
- Developer tools
- Deliverability
-
Account, billing & add-ons
- Plans, features and limits
- Plan add-ons
- User management
- Change password
- Two-factor authentication
- Switch accounts
- How to whitelist IPs
- How to add a domain space to your account
- How to request a dedicated IP
- Account reputation statuses
- How to set a billing limit on your account
- How to change your payment method
- How to change or cancel your plan
- Delete account
- About MailerSend's refund and account policies
- VAT Collection for EU Customers
- VAT Collection for UK Customers
- GST Collection for Customers in India
- GST Collection for Customers in Canada
- VAT (IVA) Collection for Customers in Chile
- How to use the MailerSend iOS app
- File manager
- Integrations
- Agency guides
- How to translate email templates automatically
- API reference ↗