Email testingSending from mailosaur

Sending email out from Mailosaur

Use the sending function in Mailosaur to simulate someone sending an email to your product.

If your product is capable of handling inbound emails, you can use Mailosaur’s sending feature to trigger this functionality in your product.

Sending an email to start a test

You can send emails within the Mailosaur Dashboard, or via the API:

  1. Go to the Servers page in the Mailosaur Dashboard.
  2. Click on a server.
  3. Click on New Message at the top of the page.
  4. Select the email address to send to. You can only send to verified external email addresses.
  5. Enter the subject and message body for the email (Note: the message body field supports Markdown syntax.)
  6. When you are finished, click Send.
await mailosaur.messages.create('{SERVER_ID}', {
  to: 'someone@example.com', // must be a verified address
  subject: 'Email from Mailosaur',
  html: '<p>Hello world.</p>',
  send: true
});
cy.mailosaurCreateMessage('{SERVER_ID}', {
  to: 'someone@example.com', // must be a verified address
  subject: 'Email from Mailosaur',
  html: '<p>Hello world.</p>',
  send: true
});
recipient = "someone@example.com" # must be a verified address
subject = "Email from Mailosaur"
body = "<p>Hello world.</p>"
options = MessageCreateOptions(
  recipient,
  True,
  subject,
  html=body
)

mailosaur.messages.create("{SERVER_ID}", options)
MessageCreateOptions options = new MessageCreateOptions();
options.withTo("someone@example.com") // must be a verified address
  .withSubject("Email from Mailosaur")
  .withHtml("<p>Hello world.</p>")
  .withSend(true);

mailosaur.messages().create("{SERVER_ID}", options);
mailosaur.Messages.Create("{SERVER_ID}", new MessageCreateOptions() {
    To = "someone@example.com", // must be a verified address
    Subject = "Email from Mailosaur",
    Html = "<p>Hello world.</p>",
    Send = true
  }
);
options = Mailosaur::Models::MessageCreateOptions.new()
options.to = 'someone@example.com' # must be a verified address
options.subject = 'Email from Mailosaur'
options.html = '<p>Hello world.</p>'
options.send = true

mailosaur.messages.create('{SERVER_ID}', options)
$options = new MessageCreateOptions();
$options->to = 'someone@example.com'; // must be a verified address
$options->subject = 'Email from Mailosaur';
$options->html = '<p>Hello world.</p>';
$options->send = TRUE;

$mailosaur->messages->create('{SERVER_ID}', $options);
m.Messages.Create("{SERVER_ID}", &MessageCreateOptions{
  To: "someone@example.com", // must be a verified address
  Subject: "Email from Mailosaur",
  Html: "<p>Hello world.</p>",
  Send: true,
})

Attachments

You can include attachments in emails sent via the API, by including an array of base64-encoded attachment objects:

const attachments = [{
  fileName: 'cat.png',
  contentType: 'image/png',
  content: '{BASE64_ENCODED_FILE}'
}];

await mailosaur.messages.create('{SERVER_ID}', {
  to: 'someone@example.com', // must be a verified address
  subject: 'Email from Mailosaur',
  html: '<p>Hello world.</p>',
  send: true,
  attachments: attachments
});
const attachments = [{
  fileName: 'cat.png',
  contentType: 'image/png',
  content: '{BASE64_ENCODED_FILE}'
}];

cy.mailosaurCreateMessage('{SERVER_ID}', {
  to: 'someone@example.com', // must be a verified address
  subject: 'Email from Mailosaur',
  html: '<p>Hello world.</p>',
  send: true,
  attachments: attachments
});
attachment = Attachment()
attachment.file_name = "cat.png"
attachment.content_type = "image/png"
attachment.content = "{BASE64_ENCODED_FILE}"
attachments = [attachment]

recipient = "someone@example.com" # must be a verified address
subject = "Email from Mailosaur"
body = "<p>Hello world.</p>"
options = MessageCreateOptions(
  recipient,
  True,
  subject,
  html=body,
  attachments=attachments
)

mailosaur.messages.create("{SERVER_ID}", options)
Attachment attachment = new Attachment();
attachment.withFileName("cat.png");
attachment.withContentType("image/png");
attachment.withContent("{BASE64_ENCODED_FILE}");

MessageCreateOptions options = new MessageCreateOptions();
options.withTo("someone@example.com") // must be a verified address
  .withSubject("Email from Mailosaur")
  .withHtml("<p>Hello world.</p>")
  .withSend(true)
  .withAttachments(Arrays.asList(new Attachment[] { attachment }));

mailosaur.messages().create("{SERVER_ID}", options);
var attachment = new Attachment()
{
  FileName = "cat.png",
  ContentType = "image/png",
  Content = "{BASE64_ENCODED_FILE}"
};

mailosaur.Messages.Create("{SERVER_ID}", new MessageCreateOptions() {
    To = "someone@example.com", // must be a verified address
    Subject = "Email from Mailosaur",
    Html = "<p>Hello world.</p>",
    Send = true,
    Attachments = new List<Attachment>() { attachment }
  }
);
attachment = Mailosaur::Models::Attachment.new()
attachment.file_name = 'cat.png'
attachment.content_type = 'image/png'
attachment.content = '{BASE64_ENCODED_FILE}'

options = Mailosaur::Models::MessageCreateOptions.new()
options.to = 'someone@example.com' # must be a verified address
options.subject = 'Email from Mailosaur'
options.html = '<p>Hello world.</p>'
options.send = true
options.attachments = [attachment]

mailosaur.messages.create('{SERVER_ID}', options)
$attachment = new Attachment((object)[
  "fileName" => "cat.png",
  "contentType" => "image/png",
  "content" => "{BASE64_ENCODED_FILE}"
]);

$options = new MessageCreateOptions();
$options->to = 'someone@example.com'; // must be a verified address
$options->subject = 'Email from Mailosaur';
$options->html = '<p>Hello world.</p>';
$options->send = TRUE;
$options->attachments = [$attachment];

$mailosaur->messages->create('{SERVER_ID}', $options);
var attachment = Attachment{
  FileName:    "cat.png",
  ContentType: "image/png",
  Content:     "{BASE64_ENCODED_FILE}",
}

m.Messages.Create("{SERVER_ID}", &MessageCreateOptions{
  To: "someone@example.com", // must be a verified address
  Subject: "Email from Mailosaur",
  Html: "<p>Hello world.</p>",
  Send: true,
  Attachments: []Attachment{attachment},
})

The content property of an attachment should be the base64-encoded content of the file you want to attach. Here’s an example of how to base64-encode a file:

const fs = require('fs');

// ...

const buffer = fs.readFileSync('/path/to/file.txt');
const content = buffer.toString('base64');
import base64

# ...

file = open('/path/to/file.txt', 'rb')
content = base64.b64encode(file.read()).decode('ascii')
byte[] data = Files.readAllBytes(Paths.get("file.txt"));
String content = new String(Base64.getEncoder().encode(data));
var data = File.ReadAllBytes("/path/to/file.txt");
var content = Convert.ToBase64String(data);
require 'base64'

# ...

data = File.open('/path/to/file.txt').read
content = Base64.encode64(data)
$data = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'path/to/file.txt');
$content = base64_encode($data);
data, _ := ioutil.ReadFile("/path/to/file.txt")
content := base64.StdEncoding.EncodeToString(data)