[Tutorial] How to add MailHog to Laragon and make it autorun using Procfile


  • administrators
    | 123747 points

    Here's how:

    1. Download MailHog:
      https://github.com/mailhog/MailHog/releases/download/v1.0.0/MailHog_windows_amd64.exe
    2. Move it to `C:\laragon\usr\bin\MailHog.exe
    3. Open Laragon's Procfile (Menu > Laragon > Procfile) and add these lines:
    MailHog: MailHog.exe autorun
    MailHog Admin: http://localhost:8025 autorun
    

    That's all. I hope you enjoyed yourself :)


  • administrators
    | 123747 points

    1 liner (using Menu > Laragon > Terminal):

    cd %LARAGON_ROOT%\usr & curl -L https://github.com/mailhog/MailHog/releases/download/v1.0.0/MailHog_windows_amd64.exe > bin\MailHog.exe & echo MailHog: MailHog.exe autorun >> Procfile & echo MailHog Admin: http://localhost:8025 autorun >> Procfile
    

  • | 1770 points

    Thank you. I opened URL and it is working.
    Just to find out how to connect it with Laragon (PHP) PHPMailer function.
    Sent few messages via contact forms on different websites and Inbox still shows (0).


  • | 389 points

    @Stagger-Lee
    MailHog will act as a local smtp server, so when you create the smtp connection with PHPMailer, you need to give it the following settings:

    MAIL_DRIVER=smtp
    MAIL_HOST=127.0.0.1
    MAIL_PORT=1025
    MAIL_USERNAME=testuser
    MAIL_PASSWORD=testpwd
    

    Ports can change depending on the config you set up MailHog with. It's also possible that it won't require any authentication... depends on the use case.


  • | 1770 points

    Thank you @blackfyre. Lost some time because of overflow of options for WordPress code. Now it is OK.

    Here it is a few lines plugin for WordPress. Just install it as any plugin. Or take action hook out and use in custom functions.php. Maybe better to install as a plugin. Later can be deleted. Less risk later will remain on production site and ruin mail sending.

    0_1521830434741_development-mail.zip


  • | 1770 points

    Is there any way to make saving mails persistent ? Some other GPL script for collecting localhost mails ? Some other solution.

    It would help a lot by tweaking newsletters, and all possible HTML format mails, contact forms. As it is now not very useful. Restart Laragon and mails are gone.


  • | 389 points

    @Stagger-Lee Mailhog isn't ment to be persistent in any way. If you want persistence, I suggest you try mailtrap.io for that.

    But I cannot imagine why would anyone want persistence for local email development... I've been doing it for years and I'm happy to see them go away at the end of the day...


  • | 2000 points

    @Stagger-Lee said in [Tutorial] How to add MailHog to Laragon and make it autorun using Procfile:

    Thank you @blackfyre. Lost some time because of overflow of options for WordPress code. Now it is OK.

    Here it is a few lines plugin for WordPress. Just install it as any plugin. Or take action hook out and use in custom functions.php. Maybe better to install as a plugin. Later can be deleted. Less risk later will remain on production site and ruin mail sending.

    0_1521830434741_development-mail.zip

    Hi,can you please re-upload? When I click on the link it says "Not Found". Thanks


  • | 1770 points

    @KoolPal said in [Tutorial] How to add MailHog to Laragon and make it autorun using Procfile:

    Hi,can you please re-upload? When I click on the link it says "Not Found". Thanks

    Will do it tonight. Sitting now on notebook without servers.


  • | 1770 points


  • | 2000 points

    Sorry. Cannot download. Can you paste the code here instead?


  • administrators
    | 123747 points

    @KoolPal: Sorry - it's the forum's issue. I've fixed it.


  • | 2000 points

    @leokhoa Not sure if @Stagger-Lee needs to re-upload the file again. I still get "not found" when I click the older links above.


  • | 2000 points

    @leokhoa
    http://localhost:8025 does not open. What step am I missing?


  • administrators
    | 123747 points

    @KoolPal : Can you show me your Procfile?


  • | 2000 points

    Okay, this is how I managed to make Mailhog work with Laragon. I would love it if anyone could share an easier way

    1. Download MailHog:
      https://github.com/mailhog/MailHog/releases/download/v1.0.0/MailHog_windows_amd64.exe
    2. Rename it to MailHog.exe
    3. Move it to `C:\laragon\usr\bin\MailHog.exe
      Open Laragon's Procfile (Menu > Laragon > Procfile) and add these lines:
      MailHog: MailHog.exe autorun
      MailHog Admin: http://localhost:8025 autorun
    4. Open F:\laragon\bin\php\php-7.1.14-Win32-VC14-x64\php.ini
      Changes:
      SMTP = localhost
      smtp_port = 1025
      sendmail_path="F:\laragon\usr\bin\MailHog.exe sendmail"
    5. Laragon settings, turn OFF Mail Catcher
    6. Restart Laragon
    7. Install Mailhog for WordPress plugin. Deactivate any SMTP plugin that may be installed like Post SMTP, etc.
    8. Run "F:\laragon\usr\bin\MailHog.exe" and keep this open for the emails to be captured.
    9. Launch http://localhost:8025/ which will only work when 8 is running.

    Is there a simpler way to make Mailhog run with Laragon?


  • | 2000 points

    @leokhoa

    # Format:
    ; Program Name: autorun COMMANDS env_file=PATH_OF_FILE pwd=PATH_OF_WORKING_DIR ENV_VAR1=VALUE ENV_VAR2="VALUE WITH SPACE"
    
    # Help:
    ; Program Name: Will be displayed on Procfile or Tools' Menu (can contains space)
    ; autorun: Your COMMANDS will be run automatically when Laragon starts
    ; COMMANDS: A command or a series of commands (separated by & )
    ; env_file: You can set environment variables directly or put them to the file
    ; PWD: Current working directory - where the COMMANDS run
    
    # Examples:
    ; My Cool App: autorun node start $PORT PORT=9000 env_file=usr\my_file.env  PWD=usr/proj/myapp DB_HOST=1.2.3.4 DB_PORT=9999 DB_USER=user DB_PASS="!$Ab.cs3cre1" DB_NAME=cooldb 
    ; Awesome Tool: "PATH HAS SPACES SHOULD BE QUOTED LIKE THIS"
    ------------------------------------------------------------------------------
    MailHog: MailHog.exe autorun
    MailHog Admin: http://localhost:8025 autorun

  • administrators
    | 123747 points

    @KoolPal : The Procfile looks good.
    It helps 8.) is autorun when you start Laragon.

    There should be 2 entries in:

    • Menu > Laragon > MailHog
    • Menu > Laragon > MailHog Admin

    What do you see when clicking Menu > Laragon > MailHog?


  • | 2000 points

    @leokhoa I see TWO options:
    0_1558955588113_upload-0844c647-5ffb-4244-a3b3-96b17a725b9a

    Clicking on the Mailhog - Autorun does nothing
    Clicking on Mailhog Admin - Autorun launches a new window at http://localhost:8025/

    Is this how it is supposed to work?


  • | 707 points

    The resources shared in this thread are fantastic. I'm able to have MailHog up and running in my local development environment exactly as I'd expect. However, there's one little thing that's bugging me...

    I want ALL email coming from PHP to go through MailHog. So, I've edited my php.ini file as @KoolPal has documented. MailHog works as expected when I reload Apache with the updated php.ini config. However, if I exit Laragon and start it back up again, the sendmail_path value is overwritten to Laragon's default sendmail config - meaning I need to go in and update it to use MailHog and reload Apache - every time I start Laragon.

    How can I prevent Laragon from overwriting the sendmail_path value on startup?

    Thanks,
    pixelbrad


Log in to reply
 

Looks like your connection to Laragon was lost, please wait while we try to reconnect.