Jump to content

WireMailSmtp


horst

Recommended Posts

5 minutes ago, fruid said:

my SMTP-server has a limited amount of emails that it can send per day. Is there a way to find out if an email was actually sent or not?

You could try sending the emails via PostMark
It's easy to integrate with WireMail SMTP, credits are cheap and it'll give you a dashboard on amounts of emails sent/bounced etc

Link to comment
Share on other sites

4 minutes ago, Peter Knight said:

You could try sending the emails via PostMark

thanks but no other service should be used. I just want to know if it's technically possible to know if an email was actually sent. I thought ->getResult() or the like would return an object of some sort.

Link to comment
Share on other sites

On 11/22/2022 at 7:17 PM, fruid said:

thanks but no other service should be used. I just want to know if it's technically possible to know if an email was actually sent. I thought ->getResult() or the like would return an object of some sort.

Taken from

getResult () - returns a dump (array) with all recipients (to, cc, bcc) and settings you have selected with the message, the message subject and body, and lists of successfull addresses and failed addresses,

So you can check with the 'recipientsFailed' entry of the array if anything went wrong.

$result = $mail->getResult();
if(count($result['recipientsSuccess']) {
// logic for successful mails
}
if(count($result['recipientsFailed']) {
// logic for failed mails
}

Or you can use return value of ->send() which returns the count of successfully sent mails or 0 on fail:

$numberSentMails = $mail->send();

Log these numbers somewhere and add some logic to your send script that counts how many mails have been sent on the current day, adds them to a mail queue or whatever you need. 

  • Like 1
Link to comment
Share on other sites

thanks @gebeer that sounds promising, will give this a try.

Follow-up question: Is there a way to switch the email sender method by API? (I very much guess so) Once the quota is reached, I’d like to try sending over the web server. So far couldn’t accomplish that.

Link to comment
Share on other sites

  • 2 weeks later...

Hi, after years of successfully using the WireMailSmtp module (thank you Horst!), today I've installed it in a new website and get the following error on send (or test settings):

syntax error, unexpected fully qualified name "\getmessage" (line 3409 in site/modules/WireMailSmtp/smtp_classes/email_message.php) 

This is the line 3409

Function GetMessage(&$message)

The PHP version is 8.0

Can anyone help?

Thank you, regards
Sebastian

Link to comment
Share on other sites

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

Hi, after years of successfully using the WireMailSmtp module (thank you Horst!), today I've installed it in a new website and get the following error on send (or test settings):

syntax error, unexpected fully qualified name "\getmessage" (line 3409 in site/modules/WireMailSmtp/smtp_classes/email_message.php) 

This is the line 3409

Function GetMessage(&$message)

The PHP version is 8.0

Can anyone help?

Thank you, regards
Sebastian

Link to comment
Share on other sites

  • 4 weeks later...

After upgrading to PHP 8.1 I get this message when sending mail:

Deprecated: Function strftime() is deprecated in /Users/XXX/Sites/processwire-ui3/site/assets/cache/FileCompiler/site/modules/WireMailSmtp/smtp_classes/email_message.php on line 675

This is no surprise - strftime() needs to be replaced in the future. It's still working fine at the moment, though. 

See email_message.php, Line 675:

return($this->FormatHeader("Message-ID", "<".strftime("%Y%m%d%H%M%S", $seconds).substr($micros,1,5).".".preg_replace('/[^A-Za-z]/', '-', $local)."@".preg_replace('/[^.A-Za-z_-]/', '', $host).">"));

I am afraid to fix this line by myself... it looks complicated ?

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

I just came across this issue and the solution is pretty simple: replace strftime() with

date("YmdHMS", $seconds)

I don't really understand the use of strftime() here since there's no use of language-dependent strings...

@horst Could you have a look at this or would you rather accept a PR?

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

On 2/28/2023 at 2:40 PM, monollonom said:

I just came across this issue and the solution is pretty simple: replace strftime() with

date("YmdHMS", $seconds)

I don't really understand the use of strftime() here since there's no use of language-dependent strings...

@horst Could you have a look at this or would you rather accept a PR?

These files are third party classes from Manuel Lemos. I first thought to wait until he has updated his files, but a PR would be pretty fine!! ??
(There are already some parts in this third party classes, that we have enhanced and or fixed on our self here.)
Thanks @monollonom!

  • Like 3
Link to comment
Share on other sites

Hey, today I saw this one in the github repo.
A pull request named "Enforce sender in emails":

-----------------

@eerojaaskelainen 

Greetings!

My 2 cents: At least Outlook 365 accounts require that address in From-field must match with username. I've added a checkbox in config to override From-address to be the same as sender defined in configuration.

Regards
Eero J.

-----------------

And he commited a PR there for. I have tested it and it works as expected, so I will merge this soon. Only thing I have to add is a) a small check with isset() for the new introduced $data['force_sender'], because otherwise PHP gives a warning about a not defined array key, when first time the config module is openend after the update to that version. And b), I have to update the module version and the change.log. ?

So, many thanks to Eero! ??

Edited by horst
  • Like 1
Link to comment
Share on other sites

7 hours ago, horst said:

Hey, today I saw this one in the github repo.
A pull request named "Enforce sender in emails":

-----------------

@eerojaaskelainen 

Greetings!

My 2 cents: At least Outlook 365 accounts require that address in From-field must match with username. I've added a checkbox in config to override From-address to be the same as sender defined in configuration.

Regards
Eero J.

-----------------

And he commited a PR there for. I have tested it and it works as expected, so I will merge this soon. Only thing I have to add is a) a small check with isset() for the new introduced $data['force_sender'], because otherwise PHP gives a warning about a not defined array key, when first time the config module is openend after the update to that version. And b), I have to update the module version and the change.log. ?

So, many thanks to Eero! ??

Can someone explain to me what this means? In case of best-practice.

Usually for the sender address I use something like noreply@mydomain.com but this address does not send the mail actually. In fact I have a separate address like mailer@mydomain.com (as SMTP user in the module settings) which sends out the mails from the forms on a website.

As far as I understand those addresses have to match in some cases?

Link to comment
Share on other sites

I just upgraded from 0.60 to 0.63, and now I’m getting the following error:

  ["ERRORS"] array(1) 
  {
    [0]      string(126) "authenticated mechanism password may not be used: it was not requested any of the authentication mechanisms that are supported"
  }
}
array(1) 
{
  ["DEBUGLOG"] string(811) "

Resolving SMTP server domain "mailout.one.com"...
Connecting to SMTP server "mailout.one.com" port 587...
Connected to SMTP server "mailout.one.com".
S 220 mailout2 ESMTP
C EHLO mysite.local
S 250-mailout2
S 250-PIPELINING
S 250-CHUNKING
S 250-SIZE 104857600
S 250-STARTTLS
S 250-AUTH LOGIN PLAIN
S 250-ENHANCEDSTATUSCODES
S 250 8BITMIME
C STARTTLS
S 220 2.0.0 Ready to start TLS
Starting TLS cryptographic protocol
TLS started: STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
C EHLO forthehearts.local
S 250-mailout2
S 250-PIPELINING
S 250-CHUNKING
S 250-SIZE 104857600
S 250-AUTH LOGIN PLAIN
S 250-ENHANCEDSTATUSCODES
S 250 8BITMIME
"
}

And this is what my provider lists as the settings it likes

Outgoing server: mailout.one.com
Port and encryption:
- 587 with STARTTLS (recommended)
- 465 with TLS
- 25 with STARTTLS or none
Authentication: your email address and password

I have it set up using 587, START-TLS and STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT

Any ideas? Fixed – see below.

Edited by Claus
Fixed the issue.
Link to comment
Share on other sites

  • 2 months later...

@horst - The latest ProcessWire DEV 3.0.220 seams to break the WireMailSmtp module (namespace fatal errors) after a module recompiling.

Class "ProcessWire\WireMailSmtp" not found

I cannot reach the settings any more and probably it does also not send out mails.

Isn't it a good idea to drop compatibility to ancient ProcessWire 2 versions and add the ProcessWire namespace in your code, so it does not compile?

  • Like 2
Link to comment
Share on other sites

15 hours ago, ceberlin said:

@horst - The latest ProcessWire DEV 3.0.220 seams to break the WireMailSmtp module (namespace fatal errors) after a module recompiling.

Class "ProcessWire\WireMailSmtp" not found

I cannot reach the settings any more and probably it does also not send out mails.

Isn't it a good idea to drop compatibility to ancient ProcessWire 2 versions and add the ProcessWire namespace in your code, so it does not compile?

Had same problem recently.

P.S. @horst, it is page 17 of WireMailSmtp support thread. Maybe it is time to split it in Module-Specific Support section?

  • Like 2
Link to comment
Share on other sites

WireMailSMTP module installed and when i test it from setting it works perfectly.

Can you give me a working simple code with html form. For Example:  Name, subject, Message 

i will use it on home page. I need an example code with html. 

Link to comment
Share on other sites

1 hour ago, kkalgidim said:

Can you give me a working simple code with html form. For Example:  Name, subject, Message 

In the first page of this thread are working examples: 

 

like: 

On 3/3/2014 at 1:36 AM, horst said:

Usage Examples

The simplest way to use it:

$numSent = wireMail($to, $from, $subject, $textBody);

$numSent = wireMail($to, '', $subject, $textBody); // or with a default sender emailaddress on config page 

This will send a plain text message to each recipient.
 
You may also use the object oriented style:

$mail = wireMail(); // calling an empty wireMail() returns a wireMail object

$mail->to($toEmail, $toName);
$mail->from = $yourEmailaddress; // if you don't have set a default sender in config
                                 // or if you want to override that
$mail->subject($subject);
$mail->body($textBody);

$numSent = $mail->send();

Or chained, like everywhere in ProcessWire:

$mail = wireMail();
$numSent = $mail->to($toEmail)->subject($subject)->body($textBody)->send(); 

Additionaly to the basics there are more options available with WireMailSmtp. The main difference compared to the WireMail BaseClass is the sendSingle option. With it you can set only one To-Recipient but additional CC-Recipients.

$mail = wireMail(); 

$mail->sendSingle(true)->to($toEmail, $toName)->cc(array('person1@example.com', 'person2@example.com', 'person3@example.com')); 

$numSent = $mail->subject($subject)->body($textBody)->send(); 

The same as function call with options array:

$options = array(
    'sendSingle' => true,
    'cc' => array('person1@example.com', 'person2@example.com', 'person3@example.com')
    );

$numSent = wireMail($to, '', $subject, $textBody, $options); 

There are methods to your disposal to check if you have the right WireMail-Class and if the SMTP-settings are working:

$mail = wireMail(); 

if($mail->className != 'WireMailSmtp') {
    // Uups, wrong WireMail-Class: do something to inform the user and quit
    echo "<p>Couldn't get the right WireMail-Module (WireMailSmtp). found: {$mail->className}</p>";
    return;
}

if(!$mail->testConnection()) {
    // Connection not working:
    echo "<p>Couldn't connect to the SMTP server. Please check the {$mail->className} modules config settings!</p>";
    return;
} 

 

 

 

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Hi Horst, is there anything in the module that would trim a recipient's TLD? I'm finding a recipient with a .solutions domain is getting their addresses trimmed to user@domain.soluti when sending via Postmark but I didn't have this issue on an earlier version of the module... not that I can remember anyway ? 

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