Setup email aliases

Email forwarding API for automatic email proxy. Setup auto-forwarding email aliases to mask a real email address.

email proxy

Email aliases let you hide an email address behind any number of generated email addresses that will forward their incoming messages to the hidden email address.

More information can be found on the alias product page. To configure forwarding to typical inboxes see the auto-forwarding rules guide.

What is an alias

Email aliases keep your email address hidden.

proxy email

An alias is an email address that can be used to mask another email address. When the alias receives an email it will be forwarded automatically to the email address it was created for.

You can manage aliases using the API, SDKs, or the dashboard.

create alias

Verification

You must manually verify an alias before it is active if the email address has not been validated for your account before.

create alias

Code example

Here is an example of how to use aliases using the official Javascript SDK and Jest.

/**
 * Example of using an email alias to mask an address and forward emails to hidden address
 */
const fetchApi = require('isomorphic-fetch');
const {
  AliasControllerApi,
  InboxControllerApi,
  Configuration,
  WaitForControllerApi,
} = require('mailslurp-client');

// setup mailslurp config
const config = new Configuration({ apiKey, fetchApi });

// create controllers
const inboxControllerApi = new InboxControllerApi(config);
const aliasControllerApi = new AliasControllerApi(config);
const waitForController = new WaitForControllerApi(config);

// create two different email addresses for testing
const inboxA = await inboxControllerApi.createInbox({ name: 'inboxA' });
const inboxB = await inboxControllerApi.createInbox({ name: 'inboxB' });
const emailAddressA = inboxA.emailAddress!!;
const emailAddressB = inboxB.emailAddress!!;

// create an alias
const alias = await aliasControllerApi.createAlias({
  createAliasOptions: {
    emailAddress: emailAddressA,
    useThreads: true,
  },
});
// emailAddressA has been masked by a new email address that was created by the alias
expect(alias.maskedEmailAddress).toEqual(emailAddressA);
expect(alias.emailAddress).not.toEqual(emailAddressA);

// alias isn't verified until you click the confirmation link sent to the aliased address
expect(alias.isVerified).toEqual(true);

Then to receive the emails:

// can send email from inboxB to alias that should be delivered to inboxA
const sent = await inboxControllerApi.sendEmailAndConfirm({
  inboxId: inboxB.id!!,
  sendEmailOptions: {
    to: [alias.emailAddress!!],
    subject: 'Hello inbox A',
    body: 'From inbox B',
  },
});

expect(sent['from']).toContain(inboxB.emailAddress);
expect(sent.to).toContain(alias.emailAddress);

// now expect email is forwarded by alias to InboxA
const forwardedEmail = await waitForController.waitForLatestEmail({
  inboxId: inboxA.id,
  unreadOnly: true,
  timeout: 30000,
});

// received message
expect(forwardedEmail.subject).toContain('Hello inbox A');
// reply to is a thread address meaning your replies can be routed through a thread
expect(forwardedEmail.replyTo).not.toEqual(emailAddressA);
expect(forwardedEmail.replyTo).not.toEqual(emailAddressB);

Other options

For information see the developers page.