Skip to content

Instructions For Setting Up Mailtrap For The Locale And Staging Environments

Welcome to the guide on setting up mailtrap for your test environment. Mailtrap is a usefull tool for intercepting test emails so they don't end up at real users or can be viewed when send to fake users.

Accessing Mailtrap

Setting Up Mailtrap For Local Use

  1. You can create your own account at: https://mailtrap.io/register/signup?ref=header.
  2. Mailtrap requires you to confirm your email address.
  3. To log into Mailtrap you can use your email and password, or one of the log in services(Google, Github, Office365) at: https://mailtrap.io/signin.
  4. On your first login Mailtrap will present a few onboarding questions to you, answer them.
  5. When confronted with the following screen pick the leftmost option titled "Email Testing" and click "start testing". Mailtrap service types
  6. You now have access to your (still empty) inbox on the left side of the screen and your Mailtrap credentials to the right. Mainly your username and password are important. The others will be the same for everyone and are mentioned in the upcomming section about setting up your .env fileMailtrap inbox and credentials

You are now done with setting up Mailtrap for local use. Feel free to move on to Setting up your .env file.

Accessing Mailtrap For The Staging environment

  1. Request the credentials needed to access the shared Mailtrap account from your team leader.
  2. Credentials in hand, head over to login at: https://mailtrap.io/signin.
  3. If/When you are prompted for a verification code just ask your team leader again.
  4. You now have access to the shared inbox on the left side of the screen and the Mailtrap credentials to the right. Mainly the username and password are important. The others will always be the same and are mentioned in the upcomming section about setting up your .env fileMailtrap inbox and credentials.

Configuring The App To Use Mailtrap

Setting Up Your Env File In A Local Environment

  1. Navigate to your .env file located at /backend/.env and open it.
  2. Find the section that configures the mailer and change these settings (if they don't exist, add them):
    javascript
    MAIL_MAILER = smtp;
    MAIL_HOST = sandbox.smtp.mailtrap.io;
    MAIL_PORT = 2525;
    MAIL_USERNAME = MailtrapUsername; //replace with the Username from the Mailtrap credentials to the right of the inbox
    MAIL_PASSWORD = MailtrapPassword; //replace with the Password from the Mailtrap credentials. You can click the password to copy it to your clipboard
    MAIL_ENCRYPTION = STARTTLS;

    TIP

    You can click your username and password on the mailtrap page to copy them to your clipboard.

  3. Don't forget to hit save!

You are now done with setting up your .env file. Feel free to move on to sending test mails locally.

Setting Up The Env File In The Staging Environment

The env file is most likely already set-up properly, so you might want to try to send a test mail first as it would save you some trouble. If the mail doesn't arrive at the inbox it is likely you need to set up the .env file.

  1. request access to the forge circle where the staging environment is running.

    WARNING

    Make sure the email address associated with your account is the same as the email address the invite is sent to, otherwise you will be denied access.

  2. Login at https://forge.laravel.com/auth/login if you arn't already.
  3. Click the "sites" button in the top bar and navigate to "staging.emmie.nl".
  4. Click "edit files" near the top right of the page and select "Edit Environment File".
  5. Find the section that configures the mailer and change these settings (if they don't exist, add them):
    javascript
    MAIL_MAILER = smtp;
    MAIL_HOST = sandbox.smtp.mailtrap.io;
    MAIL_PORT = 2525;
    MAIL_USERNAME = MailtrapUsername; //replace with the Username from the Mailtrap credentials to the right of the inbox
    MAIL_PASSWORD = MailtrapPassword; //replace with the Password from the Mailtrap credentials. You can click the password to copy it to your clipboard
    MAIL_ENCRYPTION = STARTTLS;

    TIP

    You can click your username and password on the mailtrap page to copy them to your clipboard.

  6. Click "save" and confirm by clicking "yes" in the pop-up.
  7. Near the top of the page, on the right, click "deploy now" and wait for the deployment to finish.

You are now done with setting up your .env file. Feel free to move on to sending test mails on staging.

Sending Test Mails

Sending Test Mails In A Local Environment

  1. Launch your queue service if you haven't already done so. Without the queue service the app won't actually send out any emails. You can run the following command to start your queue service:
shell
php backend/artisan queue:listen
  1. You can use the frontend interface to send mails like they would normally be send; Like Inviting clients to create an account, sending a message and triggering a notification email.

  2. Go to your mailtrap tab to check your inbox. The mail should arrive shortly.

Sending Test Mails In A Staging Environment

  1. You can use the frontend interface to send mails like they would normally be send; Like Inviting clients to create an account, sending a message and triggering a notification email.

  2. Go to your mailtrap tab to check your inbox. The mail should arrive shortly.