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 ukyo
      Call ProcessWire API Functions Inside STRING
      Github Repo
      Current status : BETA
      Each called method must return string value !
      I added all functions, but not tested all. I focused page(), page()->render and field properties (label, description and notes). I also tested some basic pages() api calls.
      Your API calls must start with { and must end with }. For use multiple arguments inside functions, separate arguments with ~ char.
      NOTE If you pass directly arguments to api {page(title)}, this call will check for requestedApiCall()->get(arguments).
      USAGE
      processString(string, page, language); Get page title <?php $str = "You are here : {page:title}"; echo processString($str); ?> Get page children render result <?php $str = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.<hr>{page:render:children}"; echo processString($str); ?> Get homepage title <?php $str = "You can visit our <a hre='{pages(1):url}'>{pages:get(1):title}</a>"; echo processString($str); ?> Get title field label, description or notes <?php $str = "Our title field properties are : label: {label(title)} - description: {description(title)} - notes: {notes(title)}"; echo processString($str); ?> Multiple examples <?php $str = " <ul class='uk-list uk-list-striped'> <li><b>01: GET FIELD LABEL</b> <code>&#123;label(title)&#125;</code> <b>RESULT :</b> <code>{label(title)}</code></li> <li><b>02: GET FIELD LABEL WITH PREFIX</b> <code>&#123;label(title~=> )&#125;</code> <b>RESULT :</b> <code>{label(title~=> )}</code></li> <li><b>03: GET FIELD LABEL WITH SUFFIX</b> <code>&#123;label(title~~ <=)&#125;</code> <b>RESULT :</b> <code>{label(title~~ <=)}</code></li> <li><b>04: GET FIELD DESCRIPTION</b> <code>&#123;description(title)&#125;</code> <b>RESULT :</b> <code>{description(title)}</code><br> <li><b>05: GET FIELD DESCRIPTION WITH PREFIX</b> <code>&#123;description(title~=> )&#125;</code> <b>RESULT :</b> <code>{description(title~=> )}</code></li> <li><b>06: GET FIELD DESCRIPTION WITH SUFFIX</b> <code>&#123;description(title~~ <=)&#125;</code> <b>RESULT :</b> <code>{description(title~~ <=)}</code></li> <li><b>07: GET FIELD NOTES</b> <code>&#123;notes(title)&#125;</code> <b>RESULT :</b> <code>{notes(title)}</code><br> <li><b>08: GET FIELD NOTES WITH PREFIX</b> <code>&#123;notes(title~=> )&#125;</code> <b>RESULT :</b> <code>{notes(title~=> )}</code></li> <li><b>09: GET FIELD NOTES WITH SUFFIX</b> <code>&#123;notes(title~~ <=)&#125;</code> <b>RESULT :</b> <code>{notes(title~~ <=)}</code></li> <li><b>10: GET PAGE TITLE</b> <code>&#123;page(title)&#125;</code> <b>RESULT :</b> <code>{page(title)}</code></li> <li><b>11: GET PAGE TITLE</b> <code>&#123;page:title&#125;</code> <b>RESULT :</b> <code>{page:title}</code></li> <li><b>12: GET PAGE RENDER TITLE</b> <code>&#123;page:render:title&#125;</code> <b>RESULT :</b> <code>{page:render:title}</code></li> <li><b>12: GET HOMEPAGE TITLE</b> <code>&#123;pages:get(template=home):title&#125;</code> <b>RESULT :</b> <code>{pages:get(template=home):title}</code></li> <li><b>13: GET HOMEPAGE TEMPLATE ID</b> <code>&#123;pages:get(template=home):template:id&#125;</code> <b>RESULT :</b> <code>{pages:get(template=home):template:id}</code></li> </ul> "; echo processString($str); ?>
    • By Robin S
      This module corrects a few things that I find awkward about the "Add New Template" workflow in the PW admin. I opened a wishlist topic a while back because it would good to resolve some of these things in the core, but this module is a stopgap for now.
      Originally I was going to share these as a few standalone hooks, but decided to bundle them together in a configurable module instead. This module should be considered alpha until it has gone through some more testing.
      Add Template Enhancements
      Adds some efficiency enhancements when adding or cloning templates via admin.

      Features
      Derive template label from name: if you like to give each of your templates a label then this feature can save some time. When one or more new templates are added in admin a label is derived automatically from the name. There are options for underscore/hyphen replacement and capitalisation of the label. Edit template after add: when adding only a single template, the template is automatically opened for editing after it is added. Copy field contexts when cloning: this copies the field contexts (a.k.a. overrides such as column width, label and description) from the source template to the new template when using the "Duplicate/clone this template?" feature on the Advanced tab. Copy field contexts when duplicating fields: this copies the field contexts if you select the "Duplicate fields used by another template" option when adding a new template. Usage
      Install the Add Template Enhancements module.
      Configure the module settings according to what suits you.
       
      https://github.com/Toutouwai/AddTemplateEnhancements
    • By AAD Web Team
      Hi,
      I've put in a support request (as a followup on an existing one) for this but it's nearly 10pm Ryan's time, so I thought I'd ask on here just in case someone can help...
      Yesterday we purchased ProDrafts, but I couldn't get the key to validate. Every time I hit submit on the module settings screen the key would be removed from the field I entered it in, and then it would complain about the missing value. I put in a support request and Ryan responded last night. It turned out it was because we're behind a proxy/firewall. He gave me a fix to get around that issue - some code to go into admin.php. I put that code in and saved admin.php, but now I can't even get into our admin anymore!
      (Just to clarify, I took the code back out and saved admin.php but that made no difference. It's definitely not the new code causing the error.)
      The errors relate to a lack of permission on the ProDrafts module (see attached screenshot). We do have a key, but evidently the code Ryan gave me to add the key in via admin.php isn't taking effect before the error is thrown...?
      I tried removing the ProDrafts directory from the modules directory, but that hasn't helped.
      Is there a hook I can put in somewhere to tell it not to load ProDrafts at all, or not check the permissions? Or is there some way to manually uninstall it from the file system?
      Thanks!
      Margaret

    • By DaveP
      I just made a textformatter module that allows you to insert dummy content (lorem ipsum style) in text fields via shortcodes.
      Usage is simple - just type for example [dc3] into a textarea with this textformatter applied (plain textarea or CKEditor) and it will be replaced at runtime by 3 paragraphs of dummy content. It can also be used to populate text fields (for headings etc) using e.g. [dc4w]. This will produce 4 words (rather than paragraphs) at runtime.
      The actual content comes from an included 'dummytext.txt' file containing 50 paragraphs of 'Lorem ipsum' from lipsum.com. The 50 paragraphs is arbitrary - it could be 10 or 100 or anything in between, and the contents of that file can be changed for your own filler text if you wish.
      The slightly clever bit is that for any given page, the same content will be returned for the same tag, but the more paragraphs available in 'dummytext.txt', the less likely it is that two pages will get the same content (very roughly speaking - it's actually based on the page ID) so content selection is determinate rather than random, even though only the tags are saved to the db.
      Update
      Tags now work like this -
      [dc3] - Show 3 paragraphs ([dc:3], [dc3p] & [dc:3p] all do the same). [dc3-6] - Show 3 to 6 paragraphs randomly per page load ([dc:3-6], [dc3-6p] & [dc:3-6p] all do the same). [dc3w] - Show 3 words ([dc:3w] does the same). [dc3-6w] - Show 3 to 6 words randomly per page load ([dc:3-6w] does the same). <End update on tags.>
      If you think it might be useful, you can download it from GitHub and give it a try.
    • By Robin S
      Password Generator
      Adds a password generator to InputfieldPassword.

       
      Usage
      Install the Password Generator module.
      Now any InputfieldPassword has a password generation feature. The settings for the generator are taken automatically from the settings* of the password field.
      *Settings not supported by the generator:
      Complexify: but generated passwords should still satisfy complexify settings in the recommended range. Banned words: but the generated passwords are random strings so actual words are unlikely to occur.  
      https://github.com/Toutouwai/PasswordGenerator