# 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. Before you can send emails, you must first verify an [external email address](/docs/managing-your-account/external-email-addresses) or [domain name](/docs/managing-your-account/managing-domains) so that you can send email to it. ## Sending an email to start a test You can send emails within the Mailosaur Dashboard, or via the API: 1. In the left-hand navigation, locate the **Inboxes** section. 2. Click on the name of an inbox. 3. Click on **Compose** at the top of the page. 4. Select the email address to send to. You can only send to [verified external email addresses](/docs/managing-your-account/external-email-addresses). 5. Enter the subject and message body for the email. 6. When you are finished, click **Send**. ```nodejs await mailosaur.messages.create('{SERVER_ID}', { to: 'someone@example.com', // must be a verified address subject: 'Email from Mailosaur', html: '

Hello world.

', send: true }); ``` ```cypress cy.mailosaurCreateMessage('{SERVER_ID}', { to: 'someone@example.com', // must be a verified address subject: 'Email from Mailosaur', html: '

Hello world.

', send: true }); ``` ```python recipient = "someone@example.com" # must be a verified address subject = "Email from Mailosaur" body = "

Hello world.

" options = MessageCreateOptions( recipient, True, subject, html=body ) mailosaur.messages.create("{SERVER_ID}", options) ``` ```java MessageCreateOptions options = new MessageCreateOptions(); options.withTo("someone@example.com") // must be a verified address .withSubject("Email from Mailosaur") .withHtml("

Hello world.

") .withSend(true); mailosaur.messages().create("{SERVER_ID}", options); ``` ```csharp mailosaur.Messages.Create("{SERVER_ID}", new MessageCreateOptions() { To = "someone@example.com", // must be a verified address Subject = "Email from Mailosaur", Html = "

Hello world.

", Send = true } ); ``` ```ruby options = Mailosaur::Models::MessageCreateOptions.new() options.to = 'someone@example.com' # must be a verified address options.subject = 'Email from Mailosaur' options.html = '

Hello world.

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

Hello world.

'; $options->send = TRUE; $mailosaur->messages->create('{SERVER_ID}', $options); ``` ```go m.Messages.Create("{SERVER_ID}", &MessageCreateOptions{ To: "someone@example.com", // must be a verified address Subject: "Email from Mailosaur", Html: "

Hello world.

", Send: true, }) ```
## Attachments You can include attachments in emails sent via the API, by including an array of base64-encoded attachment objects: ```nodejs 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: '

Hello world.

', send: true, attachments: attachments }); ``` ```cypress 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: '

Hello world.

', send: true, attachments: attachments }); ``` ```python 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 = "

Hello world.

" options = MessageCreateOptions( recipient, True, subject, html=body, attachments=attachments ) mailosaur.messages.create("{SERVER_ID}", options) ``` ```java 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("

Hello world.

") .withSend(true) .withAttachments(Arrays.asList(new Attachment[] { attachment })); mailosaur.messages().create("{SERVER_ID}", options); ``` ```csharp 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 = "

Hello world.

", Send = true, Attachments = new List() { attachment } } ); ``` ```ruby 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 = '

Hello world.

' options.send = true options.attachments = [attachment] mailosaur.messages.create('{SERVER_ID}', options) ``` ```php $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 = '

Hello world.

'; $options->send = TRUE; $options->attachments = [$attachment]; $mailosaur->messages->create('{SERVER_ID}', $options); ``` ```go 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: "

Hello world.

", 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: ```nodejs const fs = require('fs'); // ... const buffer = fs.readFileSync('/path/to/file.txt'); const content = buffer.toString('base64'); ``` ```python import base64 # ... file = open('/path/to/file.txt', 'rb') content = base64.b64encode(file.read()).decode('ascii') ``` ```java byte[] data = Files.readAllBytes(Paths.get("file.txt")); String content = new String(Base64.getEncoder().encode(data)); ``` ```csharp var data = File.ReadAllBytes("/path/to/file.txt"); var content = Convert.ToBase64String(data); ``` ```ruby require 'base64' # ... data = File.open('/path/to/file.txt').read content = Base64.encode64(data) ``` ```php $data = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'path/to/file.txt'); $content = base64_encode($data); ``` ```go data, _ := ioutil.ReadFile("/path/to/file.txt") content := base64.StdEncoding.EncodeToString(data) ```