Pierre-Luc

WireMail Mailgun

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

Share this post


Link to post
Share on other sites

everything is working fine here on Mailgun sends from processwire...

Also, i am not seeing any cURL error related issues on the github repo that you refer to. Can you link directly to such an issue?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

I can confirm that the module is still sending mails ok on my site. No errors.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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!

 

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

@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.

  • Sad 1

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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.

 

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Hey @Macrura, so glad you are taking this on. Agree it is stable, just needs a little love. In the fork made by @gebeer this supports the regions US and EU, would be great if you could get this into your fork.

  • Like 2

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Anssi
      A simple module to enable easy navigation between the public and the admin side of the site. After installation a green bar will appear to the upper side of the screen, containing a few navigation elements and displaying the PW version number.
      Heavily inspired by @apeisa's great AdminBar (Thanks!). I needed a bit simpler tool for my projects and as a result, this was made. Available on GitHub .

    • By Sebi
      I've created a small module which lets you define a timestamp after which a page should be accessible. In addition you can define a timestamp when the release should end and the page should not be accessable any more.
      Github: https://github.com/Sebiworld/PageAccessReleasetime
      Usage
      PageAccessReleasetime can be installed like every other module in ProcessWire. Check the following guide for detailed information: How-To Install or Uninstall Modules
      After that, you will find checkboxes for activating the releasetime-fields at the settings-tab of each page. You don't need to add the fields to your templates manually.
      Check e.g. the checkbox "Activate Releasetime from?" and fill in a date in the future. The page will not be accessable for your users until the given date is reached.
      If you have $config->pagefileSecure = true, the module will protect files of unreleased pages as well.
      How it works
      This module hooks into Page::viewable to prevent users to access unreleased pages:
      public function hookPageViewable($event) { $page = $event->object; $viewable = $event->return; if($viewable){ // If the page would be viewable, additionally check Releasetime and User-Permission $viewable = $this->canUserSee($page); } $event->return = $viewable; } To prevent access to the files of unreleased pages, we hook into Page::isPublic and ProcessPageView::sendFile.
      public function hookPageIsPublic($e) { $page = $e->object; if($e->return && $this->isReleaseTimeSet($page)) { $e->return = false; } } The site/assets/files/ directory of pages, which isPublic() returns false, will get a '-' as prefix. This indicates ProcessWire (with activated $config->pagefileSecure) to check the file's permissions via PHP before delivering it to the client.
      The check wether a not-public file should be accessable happens in ProcessPageView::sendFile. We throw an 404 Exception if the current user must not see the file.
      public function hookProcessPageViewSendFile($e) { $page = $e->arguments[0]; if(!$this->canUserSee($page)) { throw new Wire404Exception('File not found'); } } Additionally we hook into ProcessPageEdit::buildForm to add the PageAccessReleasetime fields to each page and move them to the settings tab.
      Limitations
      In the current version, releasetime-protected pages will appear in wire('pages')->find() queries. If you want to display a list of pages, where pages could be releasetime-protected, you should double-check with $page->viewable() wether the page can be accessed. $page->viewable() returns false, if the page is not released yet.
      If you have an idea how unreleased pages can be filtered out of ProcessWire selector queries, feel free to write an issue, comment or make a pull request!
    • By David Karich
      Thanks to the great Pro module "RepeaterMatrix" I have the possibility to create complex repeater items. With it I have created a quite powerful page builder. Many different content modules, with many more possible design options. The RepeaterMatrix module supports the cloning of items, but only within the same page. Now I often have the case that very design-intensive pages and items are created. If you want to use this module on a different page (e.g. in the same design), you have to rebuild each item manually every time.
      With this proof of concept I have created a module which adds the feature to copy a repeater item to the clipboard so that you can paste this item to another page with the same repeater field. The module has been developed very rudimentarily so far. It is currently not possible to copy nested items. There is also no check of Min/Max. You can also only copy items that have the same field on different pages. And surely you can solve all this more elegantly with AJAX. But personally I lack the deeper understanding of the repeaters. Also missing on the Javascript side are event triggers for the repeaters, which would make it easier. Like e.g. RepeaterItemInitReady or similar.
      it would be great if @ryan would implement this functionality in the core of RepeaterMatrix. I think he has better ways to implement this. Or what do you think, Ryan?
      Everybody is welcome to work on this module and improve it, if it should not be integrated into the matrix core. Therefore I put it for testing and as download on GitHub: https://github.com/FlipZoomMedia/InputfieldRepeaterMatrixDublicate
      You can best see the functionality in the screencast: 
       
    • By anderson
      Hi,
      Please take a look at this:
      https://templatemag.com/demo/Good/
      The upper nav bar, including dropdowns like "pages" and "portfolios", what do you call this whole thing? At first I guess it's called "dropdown nav bar", but seems not.
      AND of course, what's the simplest way/module to achieve this in PW?
      Thanks in advance.
    • By Sebi2020
      Hey, I'm new and I created a simple module for tagging pages because I didn't found a module for it (sadly this is not a core feature). This module is licensed under the GPL3 and cames with absolutly no warranty at all. You should test the module before using it in production environments. Currently it's an alpha release. if you like the module or have ideas for improvements feel free to post a comment. Currently this fieldtype is only compatible with the Inputfield I've created to because I haven't found  an Inputfield yet, that returns arrays from a single html input.
      Greetings Sebi2020
      FieldtypeTags.zip.asc
      InputfieldTagify.zip
      InputfieldTagify.zip.asc
      FieldtypeTags.zip