Jump to content
Pierre-Luc

WireMail Mailgun

Recommended Posts

16 hours ago, cb2004 said:

this supports the regions US and EU, would be great if you could get this into your fork.

i incorporated those elements, so those are in the module now; Should be tested by someone though, eu region on the forked version.

https://github.com/outflux3/WireMailMailgun/blob/master/WireMailMailgunConfig.php#L18-L27

https://github.com/outflux3/WireMailMailgun/blob/master/WireMailMailgun.module#L197-L205

  • Like 4

Share this post


Link to post
Share on other sites

Hey @Macrura - admittedly I haven't looked into this dynamic domain stuff much, but from what I can tell, I don't think it should be checked by default. With my setups it prevents emails from being sent.

What do you think?

Share this post


Link to post
Share on other sites

@adrian,

in order for dynamic domain to work, all of the domains have to be registered/validated in Mailgun. So for most uses the dynamic domain is not necessary. It shouldn't have been checked by default, if it was, i'll have to figure out how to make it not so.

This would only be useful for sites where you have identities that are sending from multiple domains; So for example if someone had a few forms, and one of the forms needed to have the sender email be a different domain than was entered in the form settings.

If you are in fact sending from a verified domain, and the mails are not being sent, can you check the mailgun log to see what the error code is?

Also, i should point out what happens if you don't use the dynamic domains, the emails will still go through, but will all be logged under the domain entered in the settings. The dynmaic domain just allows that config property, which is used for the CURL, to be changed on a per-message basis, setting the value of the api domain to the sender's domain (extracted from their email address). This files the messages under the correct domain logs in the Mailgun interface.

If it is not working, one possibility is that the code to extract the domain is not 100% working for all email address formats.

  • Like 1

Share this post


Link to post
Share on other sites
6 minutes ago, Macrura said:

in order for dynamic domain to work, all of the domains have to be registered/validated in Mailgun.

That makes sense - thanks.

7 minutes ago, Macrura said:

If you are in fact sending from a verified domain, and the mails are not being sent

Emails are sent just fine. I registered a mg.mydomain.com domain with Mailgun and if I use that in the module settings without dynamic domains, then everything works as expected.

9 minutes ago, Macrura said:

It shouldn't have been checked by default, if it was, i'll have to figure out how to make it not so.

I think it's simply because of the "value" parameter that is set in the WireMailMailgunConfig.php file. Actually speaking of the config settings, I think most of those checkbox settings should really have a value of "1" if they are to be checked by default, rather than the name of the field. Also, not sure what you think of the current approach to defining those module settings, but personally I prefer this approach (https://github.com/adrianbj/CookieManagementBanner/blob/master/CookieManagementBanner.config.php) if you want a separate file. No big deal either way - just seems cleaner to me. 

Share this post


Link to post
Share on other sites

i guess we do need to cleanup the checkboxes then, but i just copied the other checkbox config stuff for the new checkbox; I didn't realize that would make it checked by default; I guess this means that all of the checkboxes for this module are checked by default when you install;

  • Like 1

Share this post


Link to post
Share on other sites

Hello,

We've been using Mailgun for several years now on ProcessWire developments, using a cURL implementation within a custom site development module/template site. I'm currently rewriting that and trying to use much more of the PW API  as there's been a lot of handy things added in the past while.

Part of that process is to use WireMailMailgun, so I installed @Macrura's fork and then began to see what could be improved/finished off from the todos.

What I've ended up doing is a partial rewrite of the module:

  • to use more ProcessWire conventions and the coding style guide
  • implemented a few extra features
  • removed what I though was unnecessary code.

It requires 3.0.123 and above, as it uses the htmlToText() method from WireMail, which in turn uses WireTextTools. 

The module is here: https://github.com/chriswthomson/WireMailMailgun

Please let me know your thoughts!

Cheers,

Chris

  • Like 5

Share this post


Link to post
Share on other sites

@nbcommunication

wow thanks for this, and especially for working on the todos and cleaning up the code! Looking forward to using your improved version.

Share this post


Link to post
Share on other sites

Thanks @nbcommunication - could you please highlight the new features you've added?  I did a diff on yours vs @Macrura's but there are so many changes, it's hard to pick out what is new.

Thanks!

  • Like 1

Share this post


Link to post
Share on other sites

Hi @adrian,

A lot of the code is much the same, but tidied up with the the coding style guide implemented, so I'm not surprised the diff doesn't reveal much!

The readme is pretty thorough and covers a lot, but here's the gist:

  • addData() - add X-Mailgun-Variables - https://documentation.mailgun.com/en/latest/user_manual.html#attaching-data-to-messages - to be honest don't know what use cases there are for it but it's in the API and was easy to implement
  • addTags() - add multiple tags as an array
  • getHttpCode() - to get the response code from either send() or validateEmail() *
  • Most methods now chainable (see the Advanced Example in the readme)
  • Tracking only used if bodyHTML() is set (As this only works in HTML email)
  • cc() and bcc() only used when batchMode is off - this seems to me to be the correct implementation 
  • WireMail::htmlToText() used for generating the text version if only HTML passed (as in WireMail now)
  • The ASCII conversion for tags now uses $this->sanitizer->nameFilter($tag, [" "], "", false, 128);
  • WireMail::replyTo() implemented - doesn't seem to have been before
  • removed addAttachment(), now uses WireMail::attachment() - which adds the ability to set the filename
  • Unixtime is now passed to setDeliveryTime()
  • A bunch of other small tweaks like using $sanitizer->email() in validateEmail()

* I'd wanted to use WireHttp for the requests, but it doesn't allow custom cURL options. I have done a pull request for this, but I don't think I'll be changing the module's cURL request implementation now anyway.

Cheers,

Chris

  • Like 7
  • Thanks 1

Share this post


Link to post
Share on other sites

@nbcommunication - just wanted to say a big thanks for this new version - what are your plans to get this into the modules directory?

  • Like 1

Share this post


Link to post
Share on other sites

I’m not really sure to be honest - I haven’t added anything to the directory before so will need to have a look through the process.

A couple of points:

- is it acceptable/desirable to have a module that’s only compatible with the lastest master (123) and beyond?

- ProMailer: I’ve not looked at this myself, and don’t expect to in the near future. My assumption is that Ryan has developed this to be compatible with the initial WireMailMailgun, which has differences in batchMode for cc/bcc - maybe this wouldn’t be an issue at all, I don’t know. 

I guess what I’m trying to say is that I’d be delighted to add it to the directory, but feel that the original should be retained. Perhaps the new version should be renamed? WireMailMailgun3?

Cheers,

 

Chris

Share this post


Link to post
Share on other sites

maybe I should just replace my version with @nbcommunication's code and then see about replacing the current module with mine in the directory, or alternately, if Chris wants to keep the new version under their purview, then they could replace it. I guess we need to ask Ryan to intervene here and be able to backend edit that module record to deprecate Pierre-Luc's version...

In terms of the compatibility, I'd say that it might be preferable to (if possible) run a version check and then only utilize functionality apropos the compatible version; I do think it is a problem to have a module that is in the directory that could possibly break an installation, though if the new version does state min version required, that should be enough to prevent users from inadvertently upgrading to an incompatible version...

  • Like 3

Share this post


Link to post
Share on other sites

Agreed. I think that perhaps the best solution is for you to maintain the module, integrating anything applicable from my version. I’d be happy to help with this process.

 

  • Like 5

Share this post


Link to post
Share on other sites

ok i'll be able to work on it starting next week, and will check back in here once i have something to report...

Doh! just checked the modules directory and Ryan already made the switch... thx @ryan! Will proceed with testing now for ensuring we don't break things with the refactored code, might take a week or so on this...

  • Like 4

Share this post


Link to post
Share on other sites

Hi there,

i have installed the modul, opend an mailGun account and eveything works well except file attachment.
My code looks like this:

$m = $mail->new();
$m->to('someone@somewhere.com');
$m->from('me@myselfandi.com');
$m->subject('Test');
$m->addAttachment( $page->email_main_img->httpUrl );
$m->send();

Im wondering if i do something wrong here?

regards Simon

Share this post


Link to post
Share on other sites

@adrian - Thanks i checken the fork - looks good.

One little question: Is there anyway to embed Images and link them with CID?
I think about something like PHPMailer has: AddEmbeddedImage( $path, $cid, $name,... )

best regards
Simon

 

Share this post


Link to post
Share on other sites
2 minutes ago, simonGG said:

@adrian - Thanks i checken the fork - looks good.

One little question: Is there anyway to embed Images and link them with CID?
I think about something like PHPMailer has: AddEmbeddedImage( $path, $cid, $name,... )

I am not that familiar with the Mailgun API to know if that's an option, but without knowing the details of what you are doing I would instead recommend an HTML formatted email with an `<img>` tag to embed the image from your web server - it's generally much better to do things this way.

Share this post


Link to post
Share on other sites

That's what im used to and i wanted it to realize it that way (used cleaverreace).
But the client dont accept that images not loaded automaticly (Outlook etc.)
So i see no other option in the moment.

Share this post


Link to post
Share on other sites

Hi,

I've added an addInlineImage() method to https://github.com/chriswthomson/WireMailMailgun

<?php

$img = $pages->get(1)->images->getRandom(); // An example
$customFilename = "test.$img->ext"; // Don't want to use the basename for this example
$mg = $mail->new();
$mg->to("your@email.com")
	->subject("Test Inline Image")
	->bodyHTML("<p>Testing, 123, is there an image for you to see?</p><img src='cid:$customFilename'>")
	->addInlineImage($img->filename, $customFilename) // Second argument is optional
	->send();

If the image isn't referenced in the HTML it just appears as a standard attachment from what I can see.

Cheers,

Chris

  • Like 3

Share this post


Link to post
Share on other sites

nbcommunication

Sorry for the late reply (was totaly busy with another project) and a BIG THANKS for implementing this!

best regards


Simon

Share this post


Link to post
Share on other sites

@nbcommunication Thanks for your work on this module. Maybe @Macrura could merge your latest changes? Would you create a pull request for this?

As far as I can see everything is working fine here. I use this module in conjunction with @ryan's ProMailer module to send out newsletters.

I even used the tags method, to enable analytics.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      After forgetting the class name of the wonderful AdminPageFieldEditLinks module for what feels like the 100th time I decided I needed to give my failing memory a helping hand...
      Autocomplete Module Class Name
      Provides class name autocomplete suggestions for the "Add Module From Directory" field at Modules > New.
      Requires ProcessWire >= v3.0.16.
      Screencast

      Installation
      Install the Autocomplete Module Class Name module.
      Configuration
      Choose the type of autocomplete options list: "Module class names from directory" or "Custom list of module class names". The latter could be useful if you regularly install some modules and would prefer a shorter list of autocomplete suggestions. The list of class names in the modules directory is generated when the Autocomplete Module Class Name module is installed. It doesn't update automatically (because the retrieval of the class names is quite slow), but you can use the button underneath when you want to retrieve an updated list of class names from the directory. The "fuzzy search" option uses custom filter and item functions for Awesomplete so that the characters you type just have to exist in the module class name and occur after preceding matches but do not need to be contiguous. Uncheck this option if you prefer the standard Awesomplete matching. Custom settings for Awesomplete can be entered in the "Awesomplete options" field if needed. See the Awesomplete documentation for more information.  
      https://github.com/Toutouwai/AutocompleteModuleClassName
      https://modules.processwire.com/modules/autocomplete-module-class-name/
    • By teppo
      MarkupMenu is a markup module for generating menu trees. When provided a root page as a starting point, it generates a navigation tree (by default as a HTML "<ul>" element wrapped by a "<nav>" element) from that point onwards. If you've also provided it with current (active) page, the menu will be rendered accordingly, with current item highlighted and items rendered up to that item and its children (unless you disable the "collapsed" option, in which case the full page tree will be rendered instead).
      Modules directory: https://modules.processwire.com/modules/markup-menu/ GitHub repository: https://github.com/teppokoivula/MarkupMenu Usage
      As a markup module, MarkupMenu is intended for front-end use, but you can of course use it in a module as well. Typically you'll only need the render() method, which takes an array of options as its only argument:
      echo $modules->get('MarkupMenu')->render([ 'root_page' => $pages->get(1), 'current_page' => $page, ]); Note: if you omit root_page, site root page is used by default. If you omit current_page, the menu will be rendered, but current (active) page won't be highlighted etc.
      A slightly more complex example, based on what I'm using on one of my own sites to render a (single-level) top menu:
      echo $modules->get('MarkupMenu')->render([ 'current_page' => $page, 'templates' => [ 'nav' => '<nav class="{classes} menu--{menu_class_modifier}" aria-label="{aria_label}">%s</nav>', 'item_current' => '<a class="menu__item menu__item--current" href="{item.url}" tabindex="0" aria-label="Current page: {item.title}">{item.title}</a>', ], 'placeholders' => [ 'menu_class_modifier' => 'top', 'aria_label' => 'Main navigation', ], 'include' => [ 'root_page' => true, ], 'exclude' => [ 'level_greater_than' => 1, ], ]); Note: some things you see above may not be entirely sensible, such as the use of {menu_class_modifier} and {aria_label} placeholders. On the actual site the "nav" template is defined in site config, so I can define just these parts on a case-by-case basis while actual nav markup is maintained in one place.
      Please check out the README file for available render options. I'd very much prefer not to keep this list up to date in multiple places. Basically there are settings for defining "templates" for different parts of the menu (list, item, etc.), include array for defining rules for including in the menu and exclude array for the opposite effect, classes and placeholders arrays for overriding default classes and injecting custom placeholders, etc. 🙂
      MarkupMenu vs. MarkupSimpleNavigation
      TL;DR: this is another take on the same concept. There are many similarities, but also some differences – especially when it comes to the supported options and syntax. If you're currently using MarkupSimpleNavigation then there's probably no reason to switch over.
      I'd be surprised if anyone didn't draw lines between this module and Soma's awesome MarkupSimpleNavigation. Simply put, I've been using MSN (...) for a number of years, and it's been great – but there have been some smallish issues with it, particularly with the markup generation part, and it's also doing some things in a way that just doesn't work for me – the xtemplates thing being one of these. In many ways it's less about features, and more about style.
      In MarkupMenu I've tried to correct these little hiccups, modernise the default markup, and allow for more flexibility with placeholder variables and additional / different options. MarkupMenu was built for ProcessWire 3.0.112+ and PHP 7.1+, it's installable with Composer, and I have a few additional ideas (such as conditional placeholders) on my todo list.
      One smallish and rather specific difference is that MarkupMenu supports overriding default options via $config->MarkupMenu. I find myself redefining the default markup for every site, which until now meant that each site has a wrapper function for MarkupSimpleNavigation (to avoid code / config repetition), and this way I've been able to omit that 🙂
      Requirements
      ProcessWire >= 3.0.112 PHP >= 7.1.0 If you're working on an earlier version of ProcessWire or PHP, use MarkupSimpleNavigation instead.
    • By Robin S
      Repeater Images
      Adds options to modify Repeater fields to make them convenient for "page-per-image" usage. Using a page-per-image approach allows for additional fields to be associated with each image, to record things such as photographer, date, license, links, etc.
      When Repeater Images is enabled for a Repeater field the module changes the appearance of the Repeater inputfield to be similar (but not identical) to an Images field. The collapsed view shows a thumbnail for each Repeater item, and items can be expanded for field editing.
      Screencast

      Installation
      Install the Repeater Images module.
      Setup
      Create an image field to use in the Repeater field. Recommended settings for the image field are "Maximum files allowed" set to 1 and "Formatted value" set to "Single item (null if empty)". Create a Repeater field. Add the image field to the Repeater. If you want additional fields in the Repeater create and add these also. Repeater Images configuration
      Tick the "Activate Repeater Images for this Repeater field" checkbox. In the "Image field within Repeater" dropdown select the single image field. You must save the Repeater field settings to see any newly added Image fields in the dropdown. Adjust the image thumbnail height if you want (unlike the core Images field there is no slider to change thumbnail height within Page Edit). Note: the depth option for Repeater fields is not compatible with the Repeater Images module.
      Image uploads feature
      There is a checkbox to activate image uploads. This feature allows users to quickly and easily add images to the Repeater Images field by uploading them to an adjacent "upload" field.
      To use this feature you must add the image field selected in the Repeater Images config to the template of the page containing the Repeater Images field - immediately above or below the Repeater Images field would be a good position.
      It's recommended to set the label for this field in template context to "Upload images" or similar, and set the visibility of the field to "Closed" so that it takes up less room when it's not being used. Note that when you drag images to a closed Images field it will automatically open. You don't need to worry about the "Maximum files allowed" setting because the Repeater Images module overrides this for the upload field.
      New Repeater items will be created from the images uploaded to the upload field when the page is saved. The user can add descriptions and tags to the images while they are still in the upload field and these will be retained in the Repeater items. Images are automatically deleted from the upload field when the page is saved.
      Tips
      The "Use accordion mode?" option in the Repeater field settings is useful for keeping the inputfield compact, with only one image item open for editing at a time. The "Repeater item labels" setting determines what is shown in the thumbnail overlay on hover. Example for an image field named "image": {image.basename} ({image.width}x{image.height})  
      https://github.com/Toutouwai/RepeaterImages
      https://modules.processwire.com/modules/repeater-images/
    • By EyeDentify
      Hello There Guys.

      I am in the process of getting into making my first modules for PW and i had a question for you PHP and PW gurus in here.

      I was wondering how i could use an external library, lets say TwitterOAuth in my PW module.
      Link to library
      https://twitteroauth.com/

      Would the code below be correct or how would i go about this:
      <?PHP namespace ProcessWire; /* load the TwitterOAuth library from my Module folder */ require "twitteroauth/autoload.php"; use Abraham\TwitterOAuth\TwitterOAuth; class EyeTwitter extends WireData,TwitterOAuth implements Module { /* vars */ protected $twConnection; /* extend parent TwitterOAuth contructor $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret); */ public function myTwitterConnection ($consumer_key, $consumer_secret, $access_token, $access_token_secret) { /* save the connection for use later */ $this->twConnection = TwitterOAuth::__construct($consumer_key, $consumer_secret, $access_token, $access_token_secret); } } ?> Am i on the right trail here or i am barking up the wrong tree?
      I don´t need a complete solution, i just wonder if i am including the external library the right way.
      If not, then give me a few hint´s and i will figure it out.

      Thanks a bunch.

      /EyeDentify
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version (has been tested up to v3.3), add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "http://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


×
×
  • Create New...