Proper MailGun Setup

I signed up for Mailgun and verified a domain through DNS and all that. I configured my group_vars/all/mail.yml to have these values:

# Documentation: https://github.com/roots/trellis#mail
mail_smtp_server: smtp.mailgun.org
mail_admin: donotreply@<redacted>
mail_hostname: smtp.mailgun.org
mail_user: <redacted>
mail_password: <redacted>

I pulled the values from my active/verified domain in Mailgun. But I sent an email from Wordpress, and not only do I not get anything, the Mailgun log shows nothing.

Is there any other configuration I need to do in order to get this working?

1 Like

Did you reprovision after adding the configuration?

1 Like

Also, what environment are you on? Development, staging or production.

1 Like

mail_smtp_server might require the port as well. smtp.mailgun.org:587 for example.

But more importantly, mail_hostname is wrong. It needs to be your domain. The domain that Mailgun is configured to send email as. Anything else will just be rejected by Mailgun.

2 Likes

Sorry for the late reply everyone. Had a major issue I had to deal with most of the day.

Anyways:

@kalenjohnson : I did a vagrant destroy and vagrant up earlier today just to make sure.

@Foxaii : I am doing this on staging. Pushing to a remote server that was provisioned with the server.yml

@swalkinshaw : Good point. Know little to nothing about mail server. I tried changing mail_hostname to the verified domain in Mailgun. I also tried it with and without the the port 587.

So now I have two issues:

  1. It still doesn’t send the WooCommerce emails, and I see nothing in the logs
  2. There IS an error that popped up in the mailgun log. Looks like for a WP cron job

Failed: root@smtp.mailgun.org → deploy@smtp.mailgun.org 'Cron <deploy@localhost> curl -s http://dev.ourdomain.com/wp/wp-cron.php' Server response: 550 550 5.7.1 Relaying denied

Also, Mailhog does seem to send the emails just fine from WooCommerce, and the environments are mirror images.

Thoughts? Maybe I need to setup mailgun to run locally so I can step through the code with xdebug? Is there an easy way to do that? Or am I missing something easy?

edit below

Actually now there is a second log for the same cron, but successful. However, still no woocommerce logs. And why is it sending emails to deploy@smtp.mailgun.org?

Accepted: root@smtp.mailgun.org → deploy@smtp.mailgun.org 'Cron <deploy@localhost> curl -s http://dev.ourdomain.com/wp/wp-cron.php'

I’m also starting to see log entries where its got the correct domain, but its trying to email my donotreply@ourdomain.com. this was the subject.

*** SECURITY information for localhost***

Still trying to figure out why I can’t get my WordPress or woocommerce emails.

OK, I don’t know why, but I reboot the server, and all of a sudden the mail works. Thank you for your help! I should have known better. :disappointed:

1 Like