Jump to content

WireMailSmtp


horst

Recommended Posts

  • 3 weeks later...

Hello all,

I am trying to setup WireMailSMTP with the Gmail SMTP server, trying everything I read in this topic with no success.

The error I get that seems to say something (but I don't know what!) is =>  WireMailSmtpConfig: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbt0

The settings I am using are: (I think I entered every combination possible!)

local hostname: the site's domain (is this wrong? I don't know if it's relevant but this domain is an addon domain)

SMTP hostname: smtp.gmail.com

SMTP port: 587

use START_TLS

SMTP user: my email from Google

SMTP password: my above email password

 

Am I doing something wrong?

Link to comment
Share on other sites

2 hours ago, alan said:

In case using Google for SMTP is the problem (perhaps Google is or may one day, restrict use?), a new account with Postmark gives you 25,000 'credits', but more importantly they are great for transactional emails.

Ok, I signed up for a similar service. It works now, but I have a concern: Since my site's contact form receives emails from various people (the WireMail->from() value is different every time), I am asked to validate every single one before it passes. Is this the way these services work?

 

Link to comment
Share on other sites

7 minutes ago, alexpi said:

I am asked to validate every single one before it passes. Is this the way these services work?

I choose to have the 'From' as noreply@example.com (the domain the site is on) and I ensure that domain is valid (good SPF, DKIM etc) then one validation and you're done.

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

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. [...]

Link to comment
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
Link to comment
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
Link to comment
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 3
Link to comment
Share on other sites

  • 2 weeks later...

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

 

Link to comment
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
Link to comment
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
Link to comment
Share on other sites

  • 3 weeks later...

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?

Link to comment
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
Link to comment
Share on other sites

  • 2 weeks later...
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
Link to comment
Share on other sites

  • SebastianP changed the title to Strange PHP error in WireMailSmtp: unexpected fully qualified name "\getmessage"

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
×
×
  • Create New...