Jump to content

WireMail Mailgun


Pierre-Luc
 Share

Recommended Posts

Hi all. 

I'm assuming there's been some change over at MailGun over the past few days as this great module has stopped working on most sites that use it.

I'm getting this error in the PW MailGun logs:

cURL Error: SSL certificate problem: unable to get local issuer certificate

It seems to be fairly common over the past couple of days on the MailGun-PHP github.

Has anyone else had this issue?

  • Like 1
Link to comment
Share on other sites

Haven't seen any issues either, though the latest message was sent three days ago.

There are indeed some related issues in the mailgun-php repository, but they all seem to be closed. For an example: https://github.com/mailgun/mailgun-php/issues/174 (includes a reply from the MG folks too). Looks like they've made some certificate related updates – see the linked issue for more details and some suggestions for fixing it.

Link to comment
Share on other sites

  • 6 months later...

Mailgun have now added EU as a data territory. This has a different API url so the module will require some updating to add this option. I went to post this as an issue on Github but it looks like the repository has been changed to read only.

Link to comment
Share on other sites

1 hour ago, cb2004 said:

Mailgun have now added EU as a data territory. This has a different API url so the module will require some updating to add this option. I went to post this as an issue on Github but it looks like the repository has been changed to read only.

Could you please share a link to the mailgun docs where this is mentioned. Thank you.

EDIT: Never mind. I found it: https://documentation.mailgun.com/en/latest/api-intro.html#mailgun-regions

Link to comment
Share on other sites

  • 4 months later...

Hi @gebeer - it looks like @Pierre-Luc is no longer around here - I wonder if you might want to take over maintenance of this module?

Now to the reason I came to this thread - for some reason the Mail Interceptor panel in Tracy doesn't work with this module and so far I can't figure out why because it simply hooks into WireMail::send() which this module extends, the same as @horst's WireMailSMTP module does. Does anyone more familiar with this module have any ideas?

Thanks!

 

Link to comment
Share on other sites

OK, I kinda figured it out. These lines are the culprit:

https://github.com/plauclair/WireMailMailgun/blob/904137e349ac081eee73239bb31b0978b67a00f1/WireMailMailgun.module#L176-L183

    /**
     * Handles send() when new WireMail() is used instead
     * of calling wireMail() directly
     */
    public function send()
    {
        return $this->___send();
    }

So this seems to be triggered which prevents the hook to send() from working.

Turns out if I start my mail call with:

$m = new WireMail();

then the Mail Interceptor's hook into WireMail::send works perfectly, but it doesn't work with:

$m = wireMail() 

or:

$m = $mail->new();

Not sure how best to proceed at the moment, especially because this module doesn't seem to be maintained anymore, but I think it's probably getting quite a lot of use.

Any thoughts?

Link to comment
Share on other sites

@horst - sorry to ping you, but it's interesting because it turns out the your module doesn't work at all with the:

$m = new WireMail();

approach. So I can see why @Pierre-Luc went with that approach even though it then breaks other hooks to WireMail::send

Just wondering what your thoughts are on not supporting new WireMail() and whether maybe this module should just drop it as well?

Thanks for your thoughts - I am lost without a working MailInterceptor so I definitely would like to get this module changed so that it works without having to maintain my own hacked copy.

Link to comment
Share on other sites

6 hours ago, adrian said:

Hi @gebeer - it looks like @Pierre-Luc is no longer around here - I wonder if you might want to take over maintenance of this module?

I just extended the module with some extra methods but am not sure if I am up to maintaining it in the long run. Will have a closer look on the weekend and then get back.

  • Like 1
Link to comment
Share on other sites

On 1/10/2019 at 11:08 PM, gebeer said:

I just extended the module with some extra methods but am not sure if I am up to maintaining it in the long run. Will have a closer look on the weekend and then get back.

Thanks @gebeer - I think we really need to figure out this issue with new WireMail() not working with WireMailSMTP, but come up with another solution to what is used by this module because of the way it breaks hooking into send(). @ryan - any chance you have a minute to look into this please?

If you are willing to maintain this going forward perhaps we can replace your fork as the repo that is installed from the modules directory.

Link to comment
Share on other sites

4 hours ago, gebeer said:

@adrian  sorry for the late reply. After going through the module code, I feel maintaining this is a bit over my head. Right now I don't have the time resources to take this on. Also I have no idea why the public send method is in there, sorry.

I totally understand. It's a shame though - I feel like this module is going to be lost. I am a big fan of MailGun and I know Ryan is using this but I'd love to see that send method removed in the official version - I think it's cons outweigh its pros.

Getting a bit OT, but I think in general PW needs to figure out how to handle modules written by folks who've moved on.

Link to comment
Share on other sites

I also have made some simple customizations to this module that I feel are worth putting into the official version, and for at least 1 site that run this on, these changes are critical for the module to work. If anyone were to take it over, I could submit a pull request, or describe the change/requirement and let the maintainer implement in their interpretation of best practice.

for one, you might notice that this module's config provides a field for the 'Domain Name'. However, in my case, the 'from' email may use different domains. My Mailgun account has many domains configured.  So instead of the $options array item called CURLOPT_URL using the module's entered domain name, i need it to use the domain from the $mail instance's from/sender. To this end i created a method getDomainName() as follows:

	private function getDomainName() {
		return substr(strrchr($this->mail['from'], "@"), 1);
	}

then replace the CURLOPT_URL with

CURLOPT_URL => "{$this->apiUrl}" . $this->getDomainName() . "/messages", 

I guess for this module to be flexible enough going forward, there may need to be an additional setting, where you either enter a domain name in the module config, or you tell the module to 'auto' populate the domain name from the sender domain.

  • Like 2
Link to comment
Share on other sites

Hey @Macrura - these sound like very useful additions - I haven't had to deal with multiple domains for the one site just yet, but I can see it coming up for me shortly.

I'd love to see this module have a new life. I used to use WireMailSMTP with MailGun, but recently it started having issues with CC'ing so I decided to start using this and it's so much faster using the MailGun API compared with SMTP.

I don't suppose you'd like to step up and take on supporting this? I'd like to, but I already have way too many modules.

Cheers!

  • Like 1
Link to comment
Share on other sites

Sure, i don't see any reason I couldn't maintain the module; I think it is basically stable and we'd just need to all contribute our changes, test it and then it should be good to go... I'll try and get that setup soon..

  • Like 6
Link to comment
Share on other sites

Awesome!

Can I make a request to remove the public send() method so that it doesn't break hooks to ___send ? The catch with this is that it's a breaking change for anyone using:

new WireMail()

but I think it's an important change.

Let me know if there is anything I can do to help.

Link to comment
Share on other sites

I also re-read this thread and found out why i had to do the custom method to get the sender domain; However, the module does have the ability to change the sending domain on the fly, but it was not working at all when i posted the comment below; this could take some testing to figure out if the added method is necessary, or will be fixed once the send method observes all of the overrides.

Just tested and it is working now, and i'm able to override the sending domain upon instantiation of the mail, therefore the mods i posted above are not necessary; The new version I forked on GH only has the 1 change, which is the commenting out of the send alias.

-----

this is the fork:

https://github.com/outflux3/WireMailMailgun

and i guess once all of the changes are made and it is tested, we could try and see about getting this one switched on the modules directory.

For @adrian's dilemma, i think the easiest thing would be to have a setting in the module config that when clicked causes the module to not include the public send() method;

so the config value is checked and then we include that method from an external file, unless there is a better way. So anyone upgrading would keep the same functionality as before, but can elect to check the box to "remove the public send() " or something like that.

  • Like 2
Link to comment
Share on other sites

Thanks @Macrura!

One note about the readme - it says:

$mail = WireMail();

I think this should be changed to:

$m = $mail->new();

or at least it should get the case correct so it's wireMail() instead of WireMail()

Regarding a config setting for the public send() method. I think the way you are thinking, but I think we need to work towards it not being there by default. I think if you do a major version number bump before your fork goes into the modules directory we can get away with this. I just think it has the potential to break other modules because of the issue with hooking into send(), most notably is Tracy's Mail Interceptor which I use all the time for testing which I expect others use too.

 

Link to comment
Share on other sites

Wow, yeah i didn't know $mail was a global variable...

I updated the readme a bit; i think a lot if people might be overriding the global mail, because using the examples on this; So we should show both versions; they both seem to work the same.
 

I commented out the public send();

  • Like 1
Link to comment
Share on other sites

After further testing, it turned out that the dynamic domain is in fact necessary as i had requested it to be made to the original module author in 6/2016 (https://github.com/plauclair/WireMailMailgun/issues/7#issuecomment-228608931)

The reason is that the messages won't be filed into the correct Mailgun logs unless the CURL domain is set correctly, therefore if you ever want to send from multiple domains from an PW site, the current version of this module won't work when you are not able to override that (such as messages sent by FormBuilder).

I guess that maybe it could be achieved with a hook, but that would be too technical for most users; and people may be using this module and wondering why their messages are going in the wrong logs, or the from email is randomly being changed to postmaster@domain.com (happens when there is a mismatch between the sender domain and the CURL domain).

New version supports the option now...

 

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...