horst

WireMailSmtp

Recommended Posts

LostKobrakai    4,307

Send them from your own domain and just set the Reply-To header to the email of the contacting person. Automatically sending emails in the name of others isn't in vogue anymore with all those spammer out there.

Share this post


Link to post
Share on other sites
chrizz    33

I was wondering if it'll be possible to hook the ___send method to manipulate the recipient(s) and body of the mail. I was able to hook the method basically but I couldn't manage to manipulate the original data :/ 

Thanks in advance for any hints :)

use case for this: In debug mode (e.g. local or on staging) all mails should be send to a dedicated dropbox instead of the original recipient. This information should be added to the mail body instead.


Original e-mail - send to xy@domain.com

Hello XY,

thanks for your email. [...]

 

Manipulated e-mail - send to dropbox@developer.net

# Debug Info
# Original recipient: xy@domain.com


Hello XY,

thanks for your email. [...]

Share this post


Link to post
Share on other sites
adrian    7,647
1 minute ago, chrizz said:

use case for this: In debug mode (e.g. local or on staging) all mails should be send to a dedicated dropbox instead of the original recipient.

Not sure if it suits your needs or not, but TracyDebugger has a Mail Interceptor panel that intercepts all outgoing emails and instead shows all their details/content in the panel.

If not, I can look into changing the address like you want, but thought I'd mention that first just in case.

  • Like 1

Share this post


Link to post
Share on other sites
chrizz    33

@adrian although tracy seems to be really oversized for this use case but it is quite interesting and it works :) thanks for the tip!

Share this post


Link to post
Share on other sites
adrian    7,647

@chrizz - I am not really sure why this works - not much time to test right now, but it does.

$this->addHookBefore('WireMail::send', null, function($event) {
    $event->object->toName = 'testrecipient@gmail.com';
});

I would have thought it would be: $event->object->to, but doing that just adds another address. This seems to overwrite the existing one. Keep in mind I am not sure if this works with multiple recipients, but hopefully a decent start to get you going. Please let us know what you find.

PS - I put this in site/ready.php

  • Like 1

Share this post


Link to post
Share on other sites
chrizz    33

@adrian thanks a lot for sharing this and for pointing me in the right direction!

To clear the original values you can just pass "null" to the "to" method:
https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/WireMail.php#L152

Same works for cc & bcc, but to be honest, I only tested this in combination with WireMailSmtp. It might look different without WireMailSmtp (e.g. no cc/bcc)

The whole hook function looks like this and it works as expected.


$this->addHookBefore('WireMailSmtp::send', null, function($event) {
    
	if(!$this->config->debug) {
		// when not in debug mode do nothing
		return;
	}
	
	$mail = &$event->object;

	// store orgiginal recpients
	$recipients = array(
		'to'		=> $mail->to,
		'toName'	=> $mail->toName,
		'cc'		=> $mail->cc,
		'ccName'	=> $mail->ccName,
		'bcc'		=> $mail->bcc,
	);

	// reset all original recipients
	$mail->to(null);
	$mail->cc(null);
	$mail->bcc(null);
	
	// add debug recepient	
	$mail->to = 'Dropbox <dropbox@my-domain.com>';
	
	// create debug information for mailbody
	$debug_body = '### DEBUG INFO ###<br />';
	$debug_body .= 'TO: '.implode($recipients['to'], ', ').'<br />';
	$debug_body .= 'CC: '.implode($recipients['cc'], ', ').'<br />';
	$debug_body .= 'BCC: '.implode($recipients['bcc'], ', ').'<br />';
	$debug_body .= '### / DEBUG INFO ###<br /><br />';
	
	// replace original mailbody
	$new_mailbody = str_replace('<body>', '<body>'.$debug_body, $mail->bodyHTML);
	$mail->bodyHTML($new_mailbody);
	
	return;
	
});

 

  • Like 2

Share this post


Link to post
Share on other sites
palacios000    16

Hi, I have a problem with this module. Actually is a problem linked with another module FrontendUser, but considering FrontendUser is working fine if I uninstall wireMailSMTP, maybe there is a conflict somewhere...

The scenario is this: I'm trying to send an email from FrontendUser, the reset password email, but it doesn't work. If I check the logs I read:

Error in hnsmtp::send : 550-Verification failed for <processwire@www.mywebsite.it>

This is strange because all other emails sent from API or PW are delivered without any issue, and on wireMailSMTP settings page I have all my SMTP credentials set up correctly. Only this "reset password email" seems to load the default wireMailSMTP settings. Any idea what goes wrong? Thanks a lot

I'm on PW 3.0.50 - wireMailSMTP 0.2.3 - FrontednUser 0.9.3

 

Share this post


Link to post
Share on other sites
horst    3,958

Only thing what comes to my mind is different user rights!?

Can you somehow log user name / role for the different scenarios? (Maybe by temporarily add a log into the send function)

  • Like 1

Share this post


Link to post
Share on other sites
Robin S    2,487
10 hours ago, palacios000 said:

The scenario is this: I'm trying to send an email from FrontendUser, the reset password email, but it doesn't work.

I think maybe this module uses the core ProcessForgotPassword module. You may need to set the config option for that module: "Email address to send messages from"

2017-03-14_095826.png.417d3bf101701a796b21876185b5437e.png

  • Like 4

Share this post


Link to post
Share on other sites
palacios000    16

Sorry I can't add an attachment... The email is sent without attachment

$pdf = $homepage->pdf_marketing->url;
$mail = wireMail();
$mail->to($emailg);
$mail->subject($subject);
$mail->bodyHTML($emailMessage);
$mail->attachment($pdf);
$numSent = $mail->send();

And the log tells me

Error in $WireMailSmtp->attachFile($filename): Not existing or not readable file: /site/assets/files/1/consigli-alimentari-fit4all.pdf

And I tried absolute URL, again same error

Error in $WireMailSmtp->attachFile($filename): Not existing or not readable file: http://www.fit4all.it/site/assets/files/1/consigli-alimentari-fit4all.pdf

The file is there, available to see even from browser.

What I am doing wrong?

Share this post


Link to post
Share on other sites
adrian    7,647

@palacios000 - you need the "filename" rather than "url" of the attachment. Also if the files field allows more than one, make sure to do first() etc as well.

  • Like 4

Share this post


Link to post
Share on other sites
horst    3,958
On 6.4.2017 at 11:45 AM, palacios000 said:

THANKS @adrian ! I had to go back to the root folder, in my case "/home/accountname/public_html/site/assets/files/1/"

you need to use ->filename instead of ->url

$pdf = $homepage->pdf_marketing->filename;

 

  • Like 3

Share this post


Link to post
Share on other sites
horst    3,958
1 hour ago, ank said:

Is there a way to set the reply address ?

->reply("xxx@xxx.xx") ?

In the modules config screen you can set it under "sender_reply". Also a "sender_errors_to" is available.

58f7ce523b5fd_fireshot_screen_capture_133.png.65d465c1517632f261929bd7d23e2715.png

If you need to set it dynamically, you must go the workaround with modifying module config-settings via API. If so, you will find examples here in this thread or the forums in general.

 

you can use this:

$data = wire('modules')->getModuleConfigData("WireMailSmtp");

// or, regarding on scope,
$data = $modules->getModuleConfigData("WireMailSmtp");

than modify the reply adress:

$data["sender_reply"] = "you@example.com";

after modifying, you can write it back:

wire('modules')->saveModuleConfigData("WireMailSmtp", $data);

// or

$modules->saveModuleConfigData("WireMailSmtp", $data);
  • Like 2

Share this post


Link to post
Share on other sites
horst    3,958
2 minutes ago, ank said:

Thanks @horst,

i knew it was possible in the backend, but i was wondering if it was simple to do it dynamicly.

@ank I updated my above post with an example. ;-)

 

Share this post


Link to post
Share on other sites
LostKobrakai    4,307

If you mean "per individual email" then it works like that for all WireMails 

$mail->header("Reply-To", $emailAddress);

 

  • Like 3

Share this post


Link to post
Share on other sites
Marc    16

Is it possible to temporarily overwrite the smtp host and smtp user defined in settings with the API? I would like to send some emails using a different smtp server with different credentials from the one I entered in the module settings.

Share this post


Link to post
Share on other sites
Zeka    281

@Marc I think you can do the same with hosts.

On 19.04.2017 at 11:53 PM, horst said:

In the modules config screen you can set it under "sender_reply". Also a "sender_errors_to" is available.

58f7ce523b5fd_fireshot_screen_capture_133.png.65d465c1517632f261929bd7d23e2715.png

If you need to set it dynamically, you must go the workaround with modifying module config-settings via API. If so, you will find examples here in this thread or the forums in general.

 

you can use this:


$data = wire('modules')->getModuleConfigData("WireMailSmtp");

// or, regarding on scope,
$data = $modules->getModuleConfigData("WireMailSmtp");

than modify the reply adress:


$data["sender_reply"] = "you@example.com";

after modifying, you can write it back:


wire('modules')->saveModuleConfigData("WireMailSmtp", $data);

// or

$modules->saveModuleConfigData("WireMailSmtp", $data);
 
 
  • Like 2

Share this post


Link to post
Share on other sites
Marc    16
On 16-5-2017 at 4:33 PM, Zeka said:

@Marc I think you can do the same with hosts.

Thanks, gonna try this out :)

Share this post


Link to post
Share on other sites

Hello,

I have a big problem that I totally don't understand and it's becoming really really problematic because it's on a online shop.

The module was working before, with some "cannot connect to smtp-server!" but not so much.

But since some weeks, there is "Error in hnsmtp::send : it were not specified any valid recipients" a lot, like really a lot.

I use it like this : $mail->sendSingle(true)->to($dest)->bcc($dest_admin);

$dest and $dest_admin are email.
The emails are corrects.  

I tried multiples times but without changing anything and with the same emails, I can have 1 time the error et 9 time everything works fine...

I would really like some help :( 

Share this post


Link to post
Share on other sites
ethanbeyer    44
1 minute ago, Sonia Margollé said:

Hello,

I have a big problem that I totally don't understand and it's becoming really really problematic because it's on a online shop.

The module was working before, with some "cannot connect to smtp-server!" but not so much.

But since some weeks, there is "Error in hnsmtp::send : it were not specified any valid recipients" a lot, like really a lot.

I use it like this : $mail->sendSingle(true)->to($dest)->bcc($dest_admin);

$dest and $dest_admin are email.
The emails are corrects.  

I tried multiples times but without changing anything and with the same emails, I can have 1 time the error et 9 time everything works fine...

I would really like some help :( 

Often times when things like this happen it's because you've gone over your limit for emails to send through a particular SMTP host. Who are you trying to send through?

Share this post


Link to post
Share on other sites
1 minute ago, ethanbeyer said:

Often times when things like this happen it's because you've gone over your limit for emails to send through a particular SMTP host. Who are you trying to send through?

I use OVH 

The site is on for more than a year now,  I had a lot of "Error in hnsmtp::send : cannot connect to smtp-server!"  
even if I never change module configuration and if I check it's ok. And now the recipients ...

All the emails that I send using the module it's only to 1 recipients and sometimes another on in copy. 

smtp_config.jpg

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 bernhard
      hi everybody,
      this is a preview of a module that i'm working on for quite a long time. I needed it for an intranet office management application that i'm still working on. It makes it very easy to create very customized Datatables using the awesome jquery datatables plugin (www.datatables.net)
       
      EARLY ALPHA release!
      It's very likely that there will lots of changes to this module that may cause breaking your implementations.
       
      Module source
      sorry, removed as it changes too frequently; closed alpha - contact me if you think you can contribute
       
       
      Remarks:
      The module is intended to be used on the backend. Loading styles is at the moment only done via adding files to the $config->styles/scripts arrays. Also the communicaton to javascript is done via the $config->js() method that is built into the admin and would have to be implemented manually on frontend use. But it would not be difficult of course
      Installation:
      Nothing special here, just download + install
       
      edit: removed some parts, because i made a complete rewrite of the module! (see last posting in the thread)
       
      Customization example:
      in the screencast you see an example that i'm using in a process module. i put the table inside an InputfieldMarkup just to have the same look&feel all around the admin. you see that you could also use this module to create tables quickly and easily using @kongondo s runtime markup module.
      complete PHP code:
      $this->headline('Kundenliste'); $form = $modules->get('InputfieldForm'); // init datatables module $dt2 = $modules->get('RockDataTables2'); // setup columns // name $col = new dtCol(); $col->name = 'name'; $col->title = 'Name'; $col->data = function($page) { return $page->title; }; $dt2->cols->add($col); // type $col = new dtCol(); $col->name = 'type'; $col->data = function($page) { return $page->rockcontact_type->title; }; $dt2->cols->add($col); // modified $col = new dtCol(); $col->name = 'modified'; $col->data = function($page) { $obj = new stdClass(); $obj->timestamp = $page->modified; $obj->display = date('d.m.Y', $page->modified); return $obj; }; $dt2->cols->add($col); // setup table $dt2->id = 'dt_kundenliste'; $dt2->js('/site/modules/ProcessRockProjects/dt_kundenliste.js'); $f = $modules->get('InputfieldMarkup'); $f->value = $dt2->render(); $form->add($f); // ################################## // ajax request -> return data // non-ajax -> render form + table // ################################## if($config->ajax) { echo $dt2->getJSON($pages->find('template=rockcontact, sort=random, limit=10000')); die(); } else $out .= $form->render(); return $out; what is interesting here is this part:
      // modified $col = new dtCol(); $col->name = 'modified'; $col->data = function($page) { $obj = new stdClass(); $obj->timestamp = $page->modified; $obj->display = date('d.m.Y', $page->modified); return $obj; }; $dt2->cols->add($col); datatables support orthogonal data (https://datatables.net/extensions/buttons/examples/html5/outputFormat-orthogonal.html). a date column is a good example, because you need to DISPLAY a formatted date (like 10.02.2017) but you need to be able to SORT this column by a different value (timestamp). its very easy to accomplish this by providing both values in your json. Btw: You could also just transfer the timestamp and do the formatting on the client-side via javascript. Next Example will show ho this would work. Both cases can be necessary, it's just an example here.
      [...] removed
      Why i created this module:
      of course i know @Soma s module but i needed a lot more features and the newer datatables version. also i like to define all the columns as objects and have everything on one place. lister & markupadmindatatable: nice for basic tables but lacks of features to modify the appearance of the cell values (like rendering icons, background colors and so on) datatables provides a great frontend API for filtering, showing/hiding columns, getting data, modifying it... it also plays well together with frontend charts like google chart api in this case:
       
      todo / roadmap:
      all kinds of column filters (like seen in the example above that shows an older and bloated version of this module) support for ajax filters and pagination (currently all filtering and sorting is done on the client side. i tried it with up to 50.000 rows and got reasonable results. initial loading took around 10sec. but of course this heavily depends on the complexity of your table and your data.  
       
       
    • By Robin S
      PageListTrash
      Allows non-superusers to trash pages directly from Page List (if they have page-delete permission for that page).
      Not much to say really - the module adds a "Trash" option to the extra actions for pages in Page List. It looks and works just like the Trash action available to superusers.

      https://github.com/Toutouwai/PageListTrash/
       
      Up to you whether you think non-superusers should be trusted with simpler trashing. For most cases I like the default behaviour where editors have to jump through some more hoops - I want them to think carefully about what they are doing. But if an editor needs to trash several pages then this module might reduce frustration.
      @tpr, by now you can probably predict what I'm going to say...
      ...something to merge into AdminOnSteroids?
    • By celfred
      Hello,
      I'm desperately trying to update my website to PW 3.0.62 and I'm facing issues to to module compatibility. I was stuck with Pages2Pdf which I managed to solve bu updating the module from Github, but now it's the Pages Web Service module... and this time, I don't know wht to do
      The Module is found there. But it is quite old and I can't find it in the modules catalogue... and my site is making quite a use of it (I can't think of a way to do otherwise, sorry...)
      After adding the FileCompiler=0 to the module pages, the error I'm stuck with is :
      Fatal error: Class 'WireData' not found in /home/celfred/PlanetAlert/site/modules/ServicePages/ServicePages.module on line 22
      and I have no idea on what to do... I must admit I'm not a programmer but a middle-school teacher... (for your information, here's the site I'm talking about : http://planetalert.tuxfamily.org ) but I'm struggling hard to solve the different issues I have to face and I'm wlling to understand things. I have just spent many hours trying to make 2.8 work on my localhost (and it seems ok ) but I'd like to switch to 3.x to prepare the future
      If anyone had the will to spend a few minutes to try and help me, I would greatly appreciate.
      Thanks in advance !
      If you need more information to understand my problem, feel free to ask.
    • By dimitrios
      Hello,
      I have created a module that, given a Facebook app ID and secret, posts on Facebook on behalf of a user profile or page after a PW page is saved.
      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, a 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 used.


    • By kongondo
      Menu Builder
       
      Modules Directory
      Project Page
      Read Me (How to install, use, etc..)
      For highly customisable menus, please see this post.

      If you want a navigation that mirrors your ProcessWire page tree, the system allows you to easily create recursive menus using either vanilla PHP or Soma's great MarkupSimpleNavigation. In some cases, however, you may wish to create menus that:
      1. Do not mirror you site's page tree (hirarchies and ancestry); and
      2. You can add custom links (external to your site) to.

      That is primarily where Menu Builder comes in. It is also helpful if you:
      3. Prefer creating menus via drag and drop
      4. Have a need for menus (or other listings) that will be changing regularly or that you want to allow your admin users to edit.

      The issue of custom menus is not new here in the forums. The difference is that this module allows you to easily create such menus via drag and drop in the Admin. Actually, you can even use it to just create some list if you wanted to. In the backend, the module uses the jQueryUI plugin nestedSortable by Manuele J Sarfatti for the drag and drop and is inspired in part by the WP Custom Menu feature.
       
      Please read the Read Me completely before using this module. 
      For Complex or highly-customised menus, it is recommended to use the getMenuItems() method as detailed in this post.
       
      Features
      Ability to create menus that do not mirror your ProcessWire Page Tree hierarchy/structure Menus can contain both ProcessWire pages and custom links Create menu hierarchies and nesting via drag and drop Easily add CSS IDs and Classes to each menu item on creating the menu items (both custom and from ProcessWire pages) or post creation. Optionally set custom links to open in a new tab Change menu item titles built from ProcessWire pages (without affecting the original page). E.g. if you have a page titled 'About Us' but you want the menu item title to be 'About' Readily view the structure and settings for each menu item Menus stored as pages (note: just the menu, not the items!) Menu items stored as JSON in a field in the menu pages (empty values not stored) Add menu items from ProcessWire pages using page fields (option to choose between PageAutocomplete and AsmSelect [default]) or a Selector (e.g. template=basic-page, limit=20, sort=title). For page fields, you can specify a selector to return only those specified pages for selection in the page field (i.e. asm and autocomplete) For superusers, optionally allow markup in your menu titles, e.g. <span>About</span> Menu settings for nestedSortable - e.g. maxLevels (limit nesting levels) Advanced features (e.g. add pages via selector, menu settings) currently permissible to superadmins only (may change to be permission-based) Delete single or all menu items without deleting the menu itself Lock down menus for editing Highly configurable MarkupMenuBuilder - e.g. can pass menu id, title, name or array to render(); Passing an array means you can conditionally manipulate it before rendering, e.g. make certain menu branches visible only to certain users [the code is up to you!]  Optionally grab menu items only (as a Menu object WireArray or a normal array) and use your own code to create custom highly complex menus to meet any need. More... In the backend, ProcessMenuBuilder does the menu creation. For the frontend, menus are displayed using MarkupMenuBuilder.

      Credits

      In this module's infancy (way back!), I wanted to know more about ProcessWire modules as well as improve my PHP skills. As they say, what better way to learn than to actually create something? So, I developed this module (instead of writing PW tutorials as promised, tsk, tsk, naughty, naughty!) in my own summer of code . Props to Wanze, Soma, Pete, Antti and Ryan whose modules I studied (read copied ) to help in my module development and to Teppo for his wonderful write-up on the "Anatomy of fields in ProcessWire" that vastly improved my knowledge and understanding of how PW works. Diogo and marcus for idea about using pages (rather than a custom db table), onjegolders for his helpful UI comments, Martijn Geerts, OrganizedFellow, dazzyweb and Mike Anthony for 'pushing me' to complete this module and netcarver for help with the code.
       
      Screens