A fix was released to address case sensitivity in the Email Messages API.
The API now treats GET addresses/FRodgers@mailsac.com/messages
the same as GET addresses/frodgers@mailsac.com/messages
.
A fix was released to address case sensitivity in the Email Messages API.
The API now treats GET addresses/FRodgers@mailsac.com/messages
the same as GET addresses/frodgers@mailsac.com/messages
.
Our team will be performing database maintenance on Saturday May 22nd, 2021 from 14:00 – 16:00 UTC. During this period, API, email, and website services may be unavailable, intermittent, or slow to respond.
Updates during and on completion of the maintenance will be provided in this blog post.
UPDATE
All maintenance has been completed and the team is standing by monitoring performance. No further impact is expected.
Selenium and Mailsac can be used to test the delivery and contents of a signup email sent by a web application.
This example will demonstrate how to configure Selenium and provide code examples to automate and integrate testing with Mailsac.
Selenium is an automation tool for testing website user interfaces. It is open-source and supports multiple programming languages such as Java, Python, Javascript etc.
Selenium is not a single tool but is composed a several tools. Our example will focus on the WebDriver component. This will allow us to test our application as if a real person were operating the web browser.
The Selenium WebDriver is installed during step 2 by running npm install
.
git clone https://github.com/mailsac/selenium-js-example.git && cd ./selenium-js-example
npm install
Browser | Driver |
---|---|
Chrome | chromedriver(.exe) |
Internet Explorer | IEDriverServer.exe |
Edge | MicrosoftWebDriver.msi |
Firefox | geckodriver(.exe) |
Safari | safaridriver |
The safaridriver is included with Safari 10 for OSX El Capitan and macOS Sierra. It does require Remote Automation in the Develop Menu to be enabled.
This example will default to using Firefox. In order to use a different browser set the SELENIUM_BROWSER
environment variable.
SELENIUM_BROWSER
valuesSELENIUM_BROWSER=chrome
SELENIUM_BROWSER=firefox
SELENIUM_BROWSER=internet_explorer
SELENIUM_BROWSER=safari
SELENIUM_BROWSER=edge
SELENIUM_BROWSER=opera
The example web application consists of a single page with a form. The form accepts a username and email address.
Email will be sent using the Mailsac Outbound Message REST API. You will need to update mailsacAPIKey
with your API key. mailsacFromAddress
is the address that this example will use are the from address.
const mailsacAPIKey = ""; // Generated by mailsac. See https://mailsac.com/api-keys
const mailsacFromAddress = "web-application@mailsac.com";
To manually test email delivery, launch the example web application by running npm start
from the command line. Use a web browser to view http://localhost:3000/index.html
2. If everything went well you should see a confirmation.
3. Check the inbox of Mailsac address you send to using the form on https://mailsac.com
4. Verify the message you sent has been received.
To automate UI testing a few different components are required:
All of these components are installed when running npm install
To interact with the Mailsac API an API Key is needed. To generate a new API Key sign in to Mailsac and go to the API Keys Page.
An API Key is available for free to all registered users of Mailsac.
Configure the test to work with your API Key by adding it to the following line in ./test/test.js
const mailsacAPIKey = ""; // Generated by mailsac. See https://mailsac.com/api-keys
Before running the tests your Mailsac API key needs to be configured in ./test/test.js
and SMTP settings configured in app.js
.
The tests can be executed by running npm test
from the command line.
npm test
> selenium-tests@1.0.0 test /home/user/repos/selenium-js-example
> mocha
http-server
register new user
(node:838754) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
✓ sends email with link to example.com website (1383ms)
1 passing (1s)
The last line in the above code snippet 1 passing (1s)
shows our test passed. If the test failed, an error message will be displayed.
If you are using a browser other than Firefox you will need to add an environment variable when running the tests (eg SELENIUM_BROWSER=chrome npm test
).
This section will cover how Mocha and Selenium work together in this code example to test email delivery.
The integration tests are located in ./test/test.js
. The tests are written in Mocha, which uses a behavior driver development model. This allows for the description of tests in easy to understand language.
In the following example, the describe
block includes a description of what is being tested. The it
block describes the expected result. assert
is used to test the for truth. If the expected statement is not true, there will be an exception, and the test will fail.
describe("tests truth", () => {
it('true equals true', function() {
assert(true); // assert checks for truth
});
it('false equals false', () => {
// assert equal checks the first and second parameter are equal
assert.equal(false,false);
});
})
This section is a line by line explanation of the Mocha tests in the example. The code example is available on GitHub.
Mocha is used to call the Selenium WebDriver to perform actions on the example Web Application. The describe
block shows we are going to be testing the process of registering a new user. The it
block tells us what we expect to happen.
Inside the it
block Selenium WebDriver is instructed to:
username
and enter text in the fieldemail
and enter specified text in the fieldsubmitUserCreation
and click on itit("sends email with link to example.com website", async () => {
await driver.get(webappUrl);
await driver.findElement(webdriver.By.id("username")).sendKeys("webdriver", "ExampleUser");
await driver.findElement(webdriver.By.id("email")).sendKeys("webdriver", signupEmailAddress);
await driver.findElement(webdriver.By.id("submitUserCreation")).click();
...
Our webapp will then email the address submitted by Selenium.
There is a for
loop, following the Selenium commands, that uses the Mailsac API to fetch the mail from the specified email address. If an email isn’t found, it will retry 10 times waiting about 5 seconds between tries.
let messages = [];
for (let i = 0; i < 10; i++) {
// returns the JSON array of email message objects from mailsac.
const res = await request("https://mailsac.com")
.get(`/api/addresses/${signupEmailAddress}/messages`)
.set("Mailsac-Key", mailsacAPIKey);
messages = res.body;
if (messages.length > 0) {
break;
}
await wait(4500);
}
If no messages are received from the Mailsac API after 10 tries, assert
will create an exception and throw the error Never received messages!
. The contents of the email are checked to see if the link https://example.com
is in the email. If, the link is not found, an exception is created stating Missing / Incorrect link in email
assert(messages.length, "Never received messages!");
const link = messages[0].links.find((l) => "https://example.com");
assert(link, "Missing / Incorrect link in email");
This example can be modified to automate your team’s UI testing procedures. For another example of Mocha tests using Mailsac see the Integration Tests Blog Post.
Our forums are a great place to discuss usage of Mailsac’s API.
Github repository for all source code in this example:
https://github.com/mailsac/selenium-js-example
Investigating reports of slowness this morning beginning around 4:45am US Pacific time.
The issue has been mitigated resolved around 5:15am US pacific time.
A slow, locking query was identified to be in a critical path. It has been adjusted.
Are you tired of spending countless hours manually testing email delivery in your company? Do you want a reliable SaaS developer tool that can simplify and automate the process? Look no further than Mailsac.com!
Mailsac.com offers an easy-to-use platform for testing email delivery. With Mailsac, you can test your email sending capabilities, simulate incoming email messages, and check the delivery status of your outgoing messages. Whether you’re a developer, tester, or IT professional, Mailsac.com is the perfect tool to streamline your email testing process.
But why should you choose Mailsac.com over other email testing tools? Here are just a few reasons:
But don’t just take our word for it – here’s what some of our satisfied customers have to say:
“I’ve been using Mailsac.com for my email testing needs and I couldn’t be happier. It’s saved me so much time and effort, and the features are incredibly powerful.” – John P., Developer
“Mailsac.com has been an essential tool for our QA team. It’s helped us catch bugs and issues before they can cause any real problems, and the integration was a breeze. Support is responsive, often within an hour.” – Sarah M., QA Manager
So why wait? Sign up for a free Mailsac.com API & testing account today and start testing your email delivery with ease. With our reliable platform and powerful features, you can rest assured that your emails will always be delivered as intended.
My garden has been planted and the days are getting warmer. Next task, cleaning up. Mailsac won’t help you organize you garage or avoid the accumulation of clutter. But it can help you get rid of old emails.
The Delete All Messages in a Domain Endpoint released on March 23, 2021 can help you keep your private domain storage under the storage limit. It’s useful for deleting all messages before running integration tests.
This post will detail the different methods of bulk message deletion.
All messages in a custom domain can irrevocably be deleted.
From the Dashboard select Custom Domains → Select Domain to Mange → Advanced tab → Irreversibly Delete Email
The REST API has a commensurate endpoint for deleting all messages in a domain. It can be invoked by calling an HTTP POST https://mailsac.com/api/domains/{domain}/delete-all-domain-mail
, where {domain}
is the custom domain.
All messages in a Private Inbox can be deleted from the website or the REST API. Both methods will not delete starred messages.
From the From the Dashboard select Manage Email Addresses → Select Email Address → Purge Inbox
Messages in a Private Inbox can be deleted using the endpoint for deleting messages in a private inbox. The endpoint can be used with the HTTP DELETE
method on https://mailsac.com/api/addresses/{email}/messages
where {email}
is the private email address.
Individual messages can be deleted from both private and non-private inboxes.
From the From the Dashboard enter an inbox in the inbox viewer form and select Check The Mail!. From the Inbox, Click the message → Select Delete → Permanently Delete
Individual messages can be deleted using the delete message REST API. The endpoint can be called using an HTTP DELETE
with the URL https://mailsac.com/api/addresses/{email}/messages/{messageId}
. The {email}
parameter is the email address and the {messageId}
is identifier for the message to be deleted. The messageId
can be found by using the list messages in an inbox REST API endpoint.
At 7:40PM US West Coast Pacific time, we started a large planned database migration. Infrequent downtime is expected.
Mailsac has a REST API that can be leveraged to validate emails are being received with the correct contents. This can be useful for web applications that send customized emails to customers.
This example will demonstrate how to send an email via an SMTP server and validate the email was received. The code used in this example is available on GitHub.
Node version 12 or greater is required for this example due to the use of async
and await
.
Begin by creating a directory for the project.
mkdir mailsac-tests
cd mailsac-tests
npm init # enter project information, for test command use 'mocha'
Verify package.json
looks something like this. The most important part is "scripts": { "test": "mocha" }
{
"name": "mailsac-integration-tests",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "mocha"
},
"author": "",
"license": "ISC"
}
The test framework for this example is Mocha. It is a test framework for Javascript applications. A test framework will allow us to write tests against our code.
These directions are inspired by the Mocha Getting Started Guide.
cd mailsac-tests
npm install --save-dev mocha
mkdir test
$EDITOR test/test.js # or open with your favorite editor
This section is for people who are new to Mocha and test frameworks. Skip ahead if you know how to write tests.
Mocha follows a Behavior Driven Development (BDD) model of testing. This allows for human readable descriptions of software behavior. The first line of the code shows exactly what the following tests will test (ie describe("tests truth")
. The following lines state the expected outcome of the test (ie it(true equals true)
.
This test uses Node’s built in assert
. The first parameter passed to assert()
is checked for true. If it is true, the assert passes. If the value is false, it throws an exception. In this example, we assert that true
is true
and that false
is equal to false
.
describe("tests truth", () => {
it('true equals true', function() {
assert(true); // assert checks for truth
});
it('false equals false', () => {
// assert equal checks the first and second parameter are equal
assert.equal(false,false);
});
})
This code can be run and the test should pass. Run the test with npm test
. Confirm the test passed.
Congratulations! You have a working test.
In this example, an email will be sent to Mailsac using the ubiquitous Javascript SMTP library NodeMailer, then the test framework will call Mailsac to validate that the email was received.
There are a few Node modules that will make sending an email and interacting with the Mailsac REST API easier. NodeMailer will be used to send the email via SMTP. SuperTest will be used to call the Mailsac API.
npm install
Back in the text editor, open / create the file test.js
in the test
folder. Copy and paste the following code or see GitHub for the complete example.
const assert = require("assert");
const nodemailer = require("nodemailer");
const request = require("supertest");
// Generated by mailsac. See https://mailsac.com/api-keys
const mailsacAPIKey = "";
// Mailsac email address where the email will be sent
const mailsacToAddress = "example@mailsac.com";
// Username for smtp server authentication
const smtpUserName = "";
// Password for smtp server authentication
const smtpPassword = "";
// hostname of the smtp server
const smtpHost = "";
// port the smtp is listening on
const smtpPort = 587;
wait
FunctionThe test will contact the Mailsac API multiple times while waiting for the email to arrive. This function will be used later in a for loop while waiting for the email to arrive.
const wait = (millis) => new Promise((resolve) => setTimeout(resolve, millis));
The describe
callback describes in human readable terms what the test is going to do. The increased timeout is required because the default timeout for Mocha is 2 seconds. The test email will likely not arrive that quickly. The afterEach
section is used to delete all messages after the test runs. This prevents a leaky test.
describe("send email to mailsac", function () {
this.timeout(50000); // test can take a long time to run. This increases the default timeout for mocha
/* delete all messages in the inbox after the test runs to prevent leaky tests.
This requires the inbox to private, which is a paid feature of Mailsac.
The afterEach section could be omitted if using a public address
*/
afterEach(() =>
request("https://mailsac.com")
.delete(`/api/addresses/${mailsacToAddress}/messages`)
.set("Mailsac-Key", mailsacAPIKey)
.expect(204)
);
});
it
block and NodeMailer ConfigurationThe it
interface describes what the test will do "sends email with link to example.com website
“. The transport
variable is used to store the configuration of the SMTP server.
result = await transport.sendMail({
… Attempts to send the email and capture the result.
describe("send email to mailsac", function () {
...
it("sends email with link to example.com website", async () => {
// create a transporter object using the default SMTP transport
const transport = nodemailer.createTransport({
host: smtpHost,
port: smtpPort,
auth: {
user: smtpUserName,
pass: smtpPassword,
},
});
// send mail using the defined transport object
const result = await transport.sendMail({
from: smtpUserName, // sender address
to: mailsacToAddress, // recipient address
subject: "Hello!",
text: "Check out https://example.com",
html: "Check out <a href https://example.com>My website</a>",
});
// logs the messageId of the email, confirming the
// email was submitted to the smtp server
console.log("Sent email with messageId: ", result.messageId);
});
This section of code uses a for
loop and a http library (supertest
) to check if the message has arrived at Mailsac. The test uses the Mailsac API endpoint /api/addresses/{email}/messages
which lists all messages in an inbox.
describe("send email to mailsac", function () {
...
it("sends email with link to example.com website", async () => {
...
// Check email in the inbox 10x, waiting 5 secs in between. Once we find mail, abort the loop.
let messages = [];
for (let i = 0; i < 10; i++) {
// returns the JSON array of email message objects from mailsac.
const res = await request("https://mailsac.com")
.get(`/api/addresses/${mailsacToAddress}/messages`)
.set("Mailsac-Key", mailsacAPIKey);
messages = res.body;
if (messages.length > 0) {
break;
}
await wait(4500);
}
});
});
assert
is used twice. First, to check to see if any messages were fetched from the Mailsac inbox. This checks the length of the messages
array to see if any messages were received. The second assert is used to check for a link to http://example.com .
describe("send email to mailsac", function () {
// ...
it("sends email with link to example.com website", async () => {
// ...
let messages = [];
for (let i = 0; i < 10; i++) {
// ... await get messages from mailsac
}
assert(messages.length, "Never received messages!");
// After a message is retrieved from mailsac, the JSON object is checked to see if the link was parsed from the email and it is the correct link
const link = messages[0].links.find((l) => "https://example.com");
assert(link, "Missing / Incorrect link in email");
});
});
At this point the test code is complete and can be run using npm test
. If all went well the following output is written to the console.
npm test
If you are having some trouble with the tests, I recommend downloading the code from GitHub and running it.
git clone https://github.com/mailsac/mailsac-integration-test-examples.git
cd mailsac-integration-test-examples
npm install
$EDITOR test/test.js # or open with your favorite editor
Edit the test.js
and fill in your SMTP settings and Mailsac API key
const mailsacAPIKey = ""; // Generated by mailsac. See https://mailsac.com/api-keys
const mailsacToAddress = "example@mailsac.com"; // Mailsac email address where the email will be sent
const smtpUserName = ""; // Username for smtp server authentication
const smtpPassword = ""; // Password for smtp server authentication
const smtpHost = ""; // hostname of the smtp server
const smtpPort = 587; // port the smtp is listening on
Run test running the command npm test
in your terminal.
The example above can be used as part of your team’s quality assurance process. A real world example would be validating password reset links to customers. This test could be used to validate that when a customer requests a password reset an email is sent to them containing the correct password reset link.
If you have any questions about this example or want to talk about other implementations reach out to our community at https://forum.mailsac.com .
The Recent Activity Log now includes detailed sender and delivery information for outbound email. This empowers customers to diagnose sending issues.
The screenshot below shows a successful email delivery sent from user2@mailsac.com
to user1@mailsac.com
. The email message id, number of delivery attempts, rejection status, and time stamps are included in the logs
The screenshot below shows a failed email delivery from somebody@mailsac.com
. The message id, number of attempts, timestamp, and error message are provided.
This error message indicates that the recipients domain no-where-no-where-no-where.info
does not exist.
Mailsac API Documentation has been converted over to use OpenAPI.
The new format gives developers and quality assurance testers code samples for common programming languages (curl, Node, Python, PHP, Go, etc).
The API can be explored without writing any code using the Swagger UI Explorer. All that is needed to get started is a free Mailsac API Key (requires sign up).
In the Swagger UI Explorer, choose the Authorize button and enter your Mailsac API Key
Use the “Try it out” button to interact with any of the REST API endpoints. A curl example, request URL, response body, and headers are provided.