horst

WireMailSmtp

Recommended Posts

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

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

@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

@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

@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

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

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

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

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

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

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

@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
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
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 Robin S
      An experimental module for adding images to a field via pasting one or more URLs.
      Add Image URLs
      Allows images to be added to an images field by pasting URLs.

      Usage
      Install the Add Image URLs module.
      A "Paste URLs" button will be added to all image fields. Use the button to show a textarea where image URLs may be pasted, one per line. Images are added when the page is saved.
       
      https://github.com/Toutouwai/AddImageUrls
    • By netcarver
      This module provides a very simple interface to a set of named counters. You simply call a single function, next('name'), to pull the next value out of a counter - or to set it up if it does not yet exist. Next() takes a few extra parameters to allow you to increment by values other than 1 or to start at a certain number.
      This provides some similar functionality to the built-in page naming feature of PW, and to this module recently posted by Stikki but I think it offers a little more flexibility than either. Having said that, I do like the simplicity of Stikki's new auto-increment module.
      Module Availability
      Here is my module on Github.
      Here it is in the module repository.
      Example Usage
      Here's how this module can be used to title and name a new page by adding a couple of simple hooks to site/ready.php. This example applies to new pages using a template called 'invoice' that can be quick-added to the page tree. In order to get the following to work, you must edit the template that will be the parent of the 'invoice' template and setup the template for children to "invoice" and set the "Name Format for Children" field to something other than the default blank value (I use  title  as my value.)
      <?php /** * Function to recognise our special template. */ function isInvoiceTemplate($template) { return ($template == 'invoice'); } /** * Pre-load the page title for invoice pages with a unique value * which includes a counter component. */ $pages->addHookBefore("Pages::setupNew", function($event) { $page = $event->arguments(0); $is_invoice = isInvoiceTemplate($page->template); $no_inv_num = $page->title == ''; if ($is_invoice && $no_inv_num) { $counter_name = 'WR-' . date('Y'); $number = $this->modules->get('DatabaseCounters')->next($counter_name, 10, 5000); $page->title = $counter_name . '-' . sprintf("%06u", $number); } }); /** * Prevent ProcessPageEdit from forcing an edit of the name if we got here * through a quickAdd from ProcessPageAdd. We can do this because we * preset the title field in the Pages::setupNew hook. */ $pages->addHookAfter("ProcessPageEdit::loadPage", function($event) { $page = $event->return; $is_invoice = isInvoiceTemplate($page->template); $is_temp = $page->hasStatus(Page::statusTemp); if ($is_invoice && $is_temp) { $page->removeStatus(Page::statusTemp); $event->return = $page; } }); Note, the above code + module is one direct solution to the problem posted here by RyanJ.


      Version History
      1.0.0 The initial release.
    • By flydev
      PulsewayPush
      Send "push" from ProcessWire to Pulseway.
       
      Description
      PulsewayPush simply send a push to a Pulseway instance. If you are using this module, you probably installed Pulseway on your mobile device: you will receive notification on your mobile.
      To get more information about Pulseway, please visit their website.
      Note
      They have a free plan which include 10 notifications (push) each day.
       
      Usage
      Install the PulsewayPush module.
      Then call the module where you like in your module/template code :
      <?php $modules->get("PulsewayPush")->push("The title", "The notification message.", "elevated"); ?>  
      Hookable function
      ___push() ___notify() (the two function do the same thing)
       
      Download
      Github:  https://github.com/flydev-fr/PulsewayPush Modules Directory: https://modules.processwire.com/modules/pulseway-push/  
      Examples of use case
      I needed for our work a system which send notification to mobile device in case of a client request immediate support. Pulseway was choosen because it is already used to monitor our infrastructure.
      An idea, you could use the free plan to monitor your blog or website regarding the number of failed logins attempts (hooking Login/Register?), the automated tool then block the attacker's IP with firewall rules and send you a notification.
       

       
      - - -
      2017-11-22: added the module to the modules directory
       
    • By cosmicsafari
      Hi all,
      Just wondering if its possible to just add some basic output to my modules config page.
      I was wanting to output a bulleted list of some information which I will be pulling from a third party.
      Retrieving the data is fine i'm just not sure how to output it to the config page?
      From what I can see in the link below, it only seems like you can append form items to the page.
      https://processwire.com/blog/posts/new-module-configuration-options/
    • By netcarver
      A very simple textformatter that was inspired by Diogo's RemoveHeight textformatter.
      This one strips the height from any images and either adds a custom class or adds a max-width:100% as an embedded style.
      Github: https://github.com/netcarver/TextformatterFluidImages
      PW Repo: here.