Testing with SMTP

Use Mailosaur as a dummy SMTP server to catch every email your product sends.

Applies to:

All plans

The benefits of testing with SMTP

Whilst you can always use your server’s wildcard domain to create an unlimited number of email addresses, it is sometimes better to just send directly to Mailosaur via SMTP.

Cheaper than sending via your Email Service Provider (ESP)

If you have thousands of emails to test each day, sending these via your usual ESP (e.g. SendGrid or Amazon SES) can be unnecessarily expensive, as you’ll pay for each email you send, regardless of whether it is simply for testing purposes or not.

Sending lots of test emails via your email service provider can also be slow, as ESPs will often queue up emails and send them out in batches.

Prevent development and staging environments sending to real customers

When connecting directly to Mailosaur, every email you send is captured, regardless of who the email is sent “to”. This is great for protecting yourself from accidentally sending emails to real customers.

Where do I find my SMTP credentials?

Each server has a unique username and password usable for SMTP. To get this:

  1. Log into the Mailosaur Dashboard.
  2. Navigate to the server you want to use.
  3. Click the Settings button ( icon)
  4. Select Send via SMTP.
  5. Copy the credentials from this screen.

How do I send via SMTP?

You can use these code snippets to conditionally send directly to Mailosaur in your development and/or staging environments:

const nodemailer = require('nodemailer');

(async () => {
    const transport = nodemailer.createTransport({
        service: 'Mailosaur',
        auth: {
            user: '',
            pass: 'SMTP_PASSWORD'

    await transport.sendMail({
        subject: 'A test email',
        from: 'Our Company <>',
        to: 'Test User <>',
        html: '<p>Hello world.</p>',
        text: 'Hello world.'
import smtplib

sender = "Our Company <>"
recipient = "Test User <>"

message = f"""\
Subject: A test email
To: {recipient}
From: {sender}

Hello world."""

with smtplib.SMTP("", 2525) as server:
    server.login("", "SMTP_PASSWORD")
    server.sendmail(sender, recipient, message)
// Uses javax.mail
Properties props = new Properties();
props.put("", "");
props.put("mail.smtp.port", "2525");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.ssl.protocols", "TLSv1.2");
props.put("", "");

Session session = Session.getInstance(props, new Authenticator() {
	protected PasswordAuthentication getPasswordAuthentication() {
		return new PasswordAuthentication("", "SMTP_PASSWORD");

MimeMessage message = new MimeMessage(session);

message.setSubject("A test email");
message.setFrom(new InternetAddress("Our Company <>"));
message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress("Test User <>"));

MimeBodyPart mimeBodyPart = new MimeBodyPart();
mimeBodyPart.setContent("<p>Hello world.</p>", "text/html; charset=utf-8");

Multipart multipart = new MimeMultipart();


using MimeKit;
using MailKit.Security;
using MimeKit.Text;

var message = new MimeMessage();
message.From.Add(new MailboxAddress("Our Company", ""));
message.To.Add(new MailboxAddress("Test User", ""));
message.Subject = "A test email";

message.Body = new TextPart(TextFormat.Html)
    Text = "<p>Hello world.</p>"

using (var emailClient = new MailKit.Net.Smtp.SmtpClient())
    emailClient.Connect("", 2525, SecureSocketOptions.StartTls);
    emailClient.Authenticate("", "SMTP_PASSWORD");
require 'net/smtp'

message = <<MESSAGE_END
From: Our Company <>
To: Test User <>
Subject: A test email

Hello world.

  '', 'SMTP_PASSWORD', :cram_md5
) do |smtp|
  smtp.send_message message, '', ''
// Install with `composer require nette/mail`

$smtp = new Nette\Mail\SmtpMailer([
	'host' => '',
    'port' => 2525,
	'username' => '',
	'password' => 'SMTP_PASSWORD',
	'secure' => 'starttls',

$message = new Nette\Mail\Message;
$message->setFrom('Our Company <>')
	->addTo('Test User <>')
	->setSubject('A test email')
    ->setHtmlBody('<p>Hello world.</p>');

import (

func main() {
	from := ""
	to := []string{
	msg := []byte("From: Our Company <>\r\n" +
		"To: Test User <>\r\n" +
		"Subject: A test email\r\n\r\n" +
		"Hello world.\r\n")

	auth := smtp.CRAMMD5Auth("", "SMTP_PASSWORD")
	err := smtp.SendMail("", auth, from, to, msg)
	if err != nil {
	fmt.Println("Mail sent successfully!")