PHPList not able to connect to smtp server - server

Please guys help me.
This is my config:
$mail->SMTPAuth = true;
define('PHPMAILERHOST', 'tonyfintech.info');
$phpmailer_smtpuser = 'info#tonyfintech.info';
$phpmailer_smtppassword = 'azerty123';
$phpmailer_smtpport = '587';
$phpmailer_smtpsecure = 'tls';
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => false
)
);
define('TEST', 0);
define('PHPMAILER_SMTP_DEBUG', 1);
I still have this error:
2018-10-30 21:04:23 CLIENT -> SERVER: EHLO tonyfintech.info
2018-10-30 21:04:23 CLIENT -> SERVER: STARTTLS
SMTP Error: Could not connect to SMTP host.
2018-10-30 21:04:23 CLIENT -> SERVER: QUIT
This configuration works well in my other server but not this one.
By the way, When I send an email using PHPMailer "just for testing" , it works with no issue .
The issue come from PHPList

The fact that it works on one server but not another suggests it's an environmental problem, not your code. The most likely explanation is that your server's CA certificate bundle is outdated, which is covered extensively on here and in the PHPMailer troubleshooting guide.
You should not be disabling certificate verification, though at a guess I'd say that PHPList isn't using your PHPMailer instance, which is probably why it's failing, because the certificate verification disabling you've done only applies to PHPMailer, not PHPList.
Fix your certificates and it will work in both.

Related

Zend_Http_Client and TLS 1.2 in Zend Framework 1

I can see here how to set the socket adapter for Zend_Http_Client
http://framework.zend.com/manual/1.12/en/zend.http.client.adapters.html
The examples they give are tls or sslv2.
Does anyone know what the setting is for tls1.2?
I've tried a few but I'm just guessing. I get errors along the lines of:
Unable to find the socket transport "tls1.2" - did you forget to enable it when you configured PHP?'
If I try tls on it's own I get:
Unable to Connect to tls://www.sandbox.paypal.com:443
(For others Googling this is to fix our IPN verification with PayPal which gives the following error on our SSL connection:
Error in cURL request: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
)
You were close! Set ssltransport to tlsv1.2.
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Socket',
'ssltransport' => 'tlsv1.2'
);
$client = new Zend_Http_Client('https://www.sandbox.paypal.com', $config);
$response = $client->request();
echo $response->getStatus();
Figured it out by first checking what Zend_Http_Client_Adapter_Socket uses to send HTTP requests, which turned out to be stream_socket_client(). You can run the stream_get_transports() on your system to view the list of available socket transports.
See SSL/TLS version selection in the OpenSSL changes in PHP 5.6.x migration guide for more examples of how to select specific SSL/TLS versions.
Tested with PHP 5.6 on Ubuntu 14.04 Trusty, which supports TLSv1.2 out of the box.

Trust self-signed certificate for Email::Sender::Transport::SMTPS in perl

Trying to use Email::Sender::Transport::SMTPS for sending email. My transport is:
my $transport = Email::Sender::Transport::SMTPS->new({
host => $smtpserver,
ssl => 'starttls',
sasl_username => $smtpuser,
sasl_password => $smtppassword,
debug => 1,
});
When trying send the email, the debug says:
Net::SMTPS=GLOB(0x7f893b2b00f0)<<< 250-SIZE 52428800
Net::SMTPS=GLOB(0x7f893b2b00f0)<<< 250-8BITMIME
Net::SMTPS=GLOB(0x7f893b2b00f0)<<< 250-PIPELINING
Net::SMTPS=GLOB(0x7f893b2b00f0)<<< 250-STARTTLS
Net::SMTPS=GLOB(0x7f893b2b00f0)<<< 250 HELP
Net::SMTPS=GLOB(0x7f893b2b00f0)>>> STARTTLS
Net::SMTPS=GLOB(0x7f893b2b00f0)<<< 220 TLS go ahead
DEBUG: .../IO/Socket/SSL.pm:735: local error: SSL connect attempt failed error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
DEBUG: .../IO/Socket/SSL.pm:738: fatal SSL error: SSL connect attempt failed error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
unable to establish SMTP connection
Probably because the server using self-signed certificate. (When using the same setting in the Thunderbird it is needed to add the "trust this certificate" setting.)
The question is: How to add the "trust this certificate" for the Email::Sender::Transport::SMTPS - thus allow sending email.
There is no direct way to give Email::Sender::Transport::SMTPS SSL specific arguments. But, since ultimately IO:Socket::SSL is used you can hack your way around this limitation. From the man page:
This is a list of typical errors seen with the use of IO::Socket::SSL:. ....
Make SSL settings inacessible by the user, together with bad builtin settings.
Some modules use IO::Socket::SSL, but don't make the SSL settings available to the user. This is often combined with bad builtin settings or defaults (like switching verification off). Thus the user needs to hack around these restrictions by using set_args_filter_hack or similar.
Thus what you could do is
IO::Socket::SSL::set_args_filter_hack( sub {
my ($is_server,$args) = #_;
$args->{SSL_fingerprint} = 'sha1$437104....'
});
With this option you could make certificate pinning trust a certificate as long as it's fingerprint matches the given one. You can get the fingerprint for instance with:
openssl s_client -connect mail.example.org:25 -starttls smtp |\
openssl x509 -fingerprint -noout
Alternative ways would be to use the certificate as trusted with the SSL_ca_file option. You could also set SSL_verify_mode to 0 (SSL_VERFY_NONE) but since this disables any kind of validation you should only use this for testing.
Please note that set_args_filter_hack is global, that is it affects all IO::Socket::SSL objects in your program. Thus depending on the program you should only set it directly before you establish the connection with Email::Sender::Transport::SMTPS and reset it immediately afterwards.
For more information about these options please read the documentation of IO::Socket::SSL.
You can control the SSL usage with the options of new() constructor method
"SSL_verify_mode"=>'SSL_VERIFY_NONE'
IN Email/Sender/Transport/SMTPS.pm
# compatible
my $ssl = $self->ssl;
$ssl = 'ssl' if $self->ssl and $self->ssl ne 'starttls';
return (
$self->host,
Port => $self->port,
Timeout => $self->timeout,
defined $ssl ? (doSSL => $ssl) : (),
defined $self->helo ? (Hello => $self->helo) : (),
defined $self->localaddr ? (LocalAddr => $self->localaddr) : (),
defined $self->localport ? (LocalPort => $self->localport) : (),
defined $self->debug ? (Debug => $self->debug) : (),
"SSL_verify_mode"=>'SSL_VERIFY_NONE',#ADDED LINE
);
EDIT: This is really bad, because as per comments you trust everything. Instead if on linux/*nix
cat tobetrusted.crt >> /etc/ssl/cert.pem

Mail Exception only on server

Stage
I have a web application which I deployed recently. Application needs to send emails for several reasons.
I am using yandex business email service for my domain, have many email accounts for my domain, and I can use those email addresses without any problem.
I have written some code to send email on my Laravel application, using Laravel's Mail::send. See it below at #2. And you can see my config/mail.php settings at #1 below.
I am testing my application on my windows computer, with WAMP server.
My production server is VPS server running Linux. PHP version 5.5.29.
Problem
Everything works perfectly on my local test environment;
I can send mails, and they are delivered to hotmail, gmail or my domain's emails without any problem.
On the server however, I receive an error when I try to send an email. See #3 for error.
On the same server, I am able to send emails using PHPMailer with same email accounts, email settings and credentials, and without any problem.
Question and thoughts
Everything works on my local environment as expected and that makes me think it is a problem with my server configurations, PHP version, configuration or extensions, but I do not have the knowledge to judge that.
What have I tried and did not worked
Commented these lines to send email from default mail address.
And also changed my default email address with another one, which is also working everywhere except on production server of this project;
//$transport = Mail::getSwiftMailer()->getTransport();
//$transport->setUsername($username);
//$transport->setPassword($password);
Disabled mail encryption. Set;
'encryption' => '',
Tried different driver;
'driver' => 'mail',
1) My config/mail.php
'driver' => 'smtp',
'host' => 'smtp.yandex.com',
'port' => 587,
'from' => ['address' => 'name#domain.com', 'name' => 'name'],
'encryption' => 'tls',
'username' => 'name#domain.com',
'password' => 'password',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
2) Code I use
Mail::send($message, $data, function ($message) use ($account, $to, $subject)
{
$acc = config("mail.accounts.$account");
$senderAddress = array_get($acc, 'address');
$username = array_get($acc, 'username', $senderAddress);
$password = array_get($acc, 'password', '');
$senderName = array_get($acc, 'name', $acc['address'], $senderAddress);
$replyToAddress = array_get($acc, 'replyTo.0', $senderAddress);
$replyToName = array_get($acc, 'replyTo.1', $senderName);
$message->from($senderAddress, $senderName)
->replyTo($replyToAddress, $replyToName)
->subject($subject)
->to($to);
$transport = Mail::getSwiftMailer()->getTransport();
$transport->setUsername($username);
$transport->setPassword($password);
});
Explanation for code above:
This code basically allows me to send emails to any email account,
and from many email accounts I have. And like I said, this works perfectly on my local test environment.
3) The Error
Swift_TransportException in AuthHandler.php line 181:
Failed to authenticate on SMTP server with username
"name#domain.com" using 2 possible authenticators
4) Working PHPMailer Script
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.yandex.com";
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->Username = $sender; // SMTP account username
$mail->Password = $password; // SMTP account password
$mail->SetFrom($sender, 'Name');
$mail->AddReplyTo($sender, 'Name');
$mail->Subject = $subject;
$mail->MsgHTML($message);
$mail->AddAddress($to, $to);
$mail->Send();
It's hard to say what the problem can be. Or why it works on your development environment. But a quick google search gave me the following settings for smpt.yandex.com:
mail server address — smtp.yandex.com;
connection security — SSL;
port — 465.
So, it shouldn't work on your dev environment. Why it does work is a mystery to me.
see: https://yandex.com/support/mail/mail-clients.xml

SMTP Error <<: 503 AUTH command used when not advertised

I am facing this error in Webmail Lite.
I have Exim installed. Here is a snippet of the auth block:
PLAIN:
driver = plaintext
server_set_id = $auth2
server_prompts = :
.ifndef AUTH_SERVER_ALLOW_NOTLS_PASSWORDS
server_advertise_condition = ${if eq{$tls_cipher}{}{}{*}}
.endif
server_condition = “${if crypteq{$auth3}{${extract{1}{:}{${lookup{$auth2}lsearch{/etc/$domain/passwd}{$value}{*:*}}}}}{1}{0}}”
I have the passwd stored in the following format:
username:{MD5}asddfasdlasdkandlanskfdaf
How do I get AUTH enabled and working ?
Thanks in advance.
One reason for this error message is sending HELO instead of EHLO, or sending EHLO in the wrong order.
But this message can occur even if EHLO is used, when the server is running Exim.
On my server, I found the solution. In WHM > Home > Service Configuration > Exim
Configuration Manager, the option "Require clients to connect with SSL
or issue the STARTTLS command before they are allowed to authenticate
with the server" was set to the default (On). I'm not sure if I did this
or not, and it is ordinarily a great idea for security, but forces the
mailserver to enable (advertise) only the STARTTLS command, not AUTH. So
when my script sends AUTH, the error message the server sends is correct.
Further information is at http://blog.networkpresence.co/?p=8923 .
Someday when I have time I will find out how to change my script to use
TLS, so I can turn that Exim option On for security.
In my case,this error not coming regularly.some time it works but some time it gives this error.(SMTP Error: Could not authenticate.)
I debug this then I found this
SMTP -> get_lines(): $data was ""
SMTP -> get_lines(): $str is "503 AUTH command used when not advertised "
SMTP -> get_lines(): $data is "503 AUTH command used when not advertised "
SMTP -> FROM SERVER:503 AUTH command used when not advertised
SMTP -> ERROR: RSET failed: 503 AUTH command used when not advertised
SMTP Error: Could not authenticate.

Postfix & Rails 3.0 ActionMailer: lost connection after STARTTLS

I'm using Ruby 1.9.2 and Rails 3.0.4 in development mode and I'm trying to configure it to send emails from the Postfix server installed on the same box (Running Ubuntu 10.04 with the dovecot-postfix package installed) Whenever I attempt to send an email from Rails, it goes through cleanly in Rails but displays an error in the Postfix logs (I've removed domains and IPs from the excerpt below):
Feb 21 04:49:16 alpha postfix/smtpd[9060]: connect from alpha.mydomain.com[xxx.xxx.xxx.xxx]
Feb 21 04:49:16 alpha postfix/smtpd[9060]: lost connection after STARTTLS from alpha.mydomain.com[xxx.xxx.xxx.xxx]
Feb 21 04:49:16 alpha postfix/smtpd[9060]: disconnect from alpha.mydomain.com[xxx.xxx.xxx.xxx]
The strange part is that when I connect to the SMTP server from an email client like Thunderbird, it works with no problems.
I know development mode sometimes doesn't allow for sending emails so I added the following to the environments/development.rb file:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
#load mail server settings
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "mail.mydomain.com",
:port => 587,
:domain => 'mydomain.com',
:user_name => 'username',
:password => 'password',
:authentication => 'plain',
:tls => true,
:enable_starttls_auto => true }
If you're just sending email from localhost, then you don't need SMTP and all the authentication issues that come with it. You can simply deliver with sendmail directly.
config.action_mailer.delivery_method = :sendmail
Is it possible that your certificate is not valid, and that Thunderbird falls back to plain SMTP when sending emails? Try disabling TLS in your config.