Chassis / MailHog

Catch all the emails WordPress sends while you're developing using Chassis!
6 stars 3 forks source link

MailHog doesn't catch emails #16

Closed Simek11 closed 6 years ago

Simek11 commented 6 years ago

I've installed MailHog extension but couldn't make it work. When I open MailHog in a browser I see some errors in JavaScript console:

[Deprecation] The Notification API may no longer be used from insecure origins. You should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details. controllers.js:102`

Failed to load resource: the server responded with a status of 404 (Not Found) :8025/api/v2/jim/:1

I've looked for a mailhog.log file but the /var/log/mailhog directory doesn't exist.

My environment:

What can be a reason of this problem?

mishterk commented 6 years ago

I'm in a similar boat for a project – mail is being sent using the wp_mail function, but MailHog isn't catching anything and there is no MailHog log.

If someone can give us direction on how to debug this, that would be rad.

I've tried:

No luck so far.

BronsonQuick commented 6 years ago

Hey folks,

I've just had a look into this and it looks like creating a mu-plugin with this code will get it working again:

<?php
/**
 * Plugin Name: Fix MailHog
 * Description: Configure WordPress on Chassis to use MailHog
 * Version:     0.1
 */

function mailhog_config( $phpmailer ) {
    // Define that we are sending with SMTP
    $phpmailer->isSMTP();

    // The hostname of the mailserver
    $phpmailer->Host = 'localhost';

    // Use SMTP authentication
    $phpmailer->SMTPAuth = false;

    // SMTP port number. Mailhog normally runs on port 1025
    $phpmailer->Port = WP_DEBUG ? '1025' : '25';

    $phpmailer->From = 'wordpress@vagrant.local';
    $phpmailer->FromName = 'Chassis';
}

add_action( 'phpmailer_init', 'mailhog_config' );

Ideally we don't want Chassis putting a plugin into the content directory as we try not to put anything into that as that code should be under version control and the developer should have control over what goes into it.

I had a quick look into this and change work out what's changed to make this happen. I might try digging into this more later today. My first initial thought is that PHPMailer has probably been updated in WordPress core to introduce this issue.

mishterk commented 6 years ago

Thanks @BronsonQuick. This is working and will keep me going until you get time to work out what needs changing.

Had a look at the extension to see if I could have a crack at it, but just don't quite understand enough of how Puppet works...I'd likely break something :)

BronsonQuick commented 6 years ago

@mishterk Awesome. I'm glad that's enough to keep you going for now!

Haha yeah no problem. Puppet is pretty different. Thanks for having a look into it. Most appreciated!

rmccue commented 6 years ago

@BronsonQuick So, the way it should work is by configuring the mail() function in PHP to redirect mail to the MailHog sendmail handler. This is provisioned in php.pp. I suspect we need to update this to place it in a different spot, given all the changes we've made around that.

(You shouldn't need any config on the WP side.)

BronsonQuick commented 6 years ago

@rmccue Champion! I was hoping you'd see this and have a better idea πŸ•ΊπŸΌ! I'll have a play around with that tonight to see if I can come up with a fix.

mishterk commented 6 years ago

Thanks @BronsonQuick – appreciate the quick turnaround :+1:

BronsonQuick commented 6 years ago

@mishterk No problem! I would've got to it sooner for @Simek11 but I was on leave!

Simek11 commented 6 years ago

@BronsonQuick Thank you. I'm glad that everything's fine now.