Problem with sending emaisl via own mailserv with TLS :-(

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
Taisa
Forum Newbie
Posts: 7
Joined: Wed Dec 24, 2008 6:14 am

Problem with sending emaisl via own mailserv with TLS :-(

Post by Taisa »

I have some kind of problem with sending email through my emailserver...
Fatal error: Uncaught exception 'Swift_ConnectionException' with message 'The SMTP connection failed to start [tls://bluebyte.net.pl:465]: fsockopen returned Error Number 10060 and Error String 'Próba po?šczenia nie powiod?a si?, poniewa? po?šczona strona nie odpowiedzia?a poprawnie po ustalonym okresie czasu lub utworzone po?šczenie nie powiod?o si?, poniewa? po?šczony host nie odpowiedzia?. '' in E:\AppServ 2.4.6\www\air2\funkcje\swift_mailer_v3.3.3\Swift\Connection\SMTP.php:309 Stack trace: #0 E:\AppServ 2.4.6\www\air2\funkcje\swift_mailer_v3.3.3\Swift.php(216): Swift_Connection_SMTP->start() #1 E:\AppServ 2.4.6\www\air2\funkcje\swift_mailer_v3.3.3\Swift.php(101): Swift->connect() #2 E:\AppServ 2.4.6\www\air2\testowy2.php(10): Swift->__construct(Object(Swift_Connection_SMTP)) #3 {main} thrown in E:\AppServ 2.4.6\www\air2\funkcje\swift_mailer_v3.3.3\Swift\Connection\SMTP.php on line 309
Telling the truth I don`t know what kind of autheticator should I use...

when I`m login on my mailserver it looks like this...

Code: Select all

 
bb-mailserv:~# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 bb-mailserv.bluebyte.net.pl ESMTP Postfix (Debian/GNU)
ehlo bluebyte.net.pl
250-bb-mailserv.bluebyte.net.pl
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
 
using this code I found nothing in my mailserv logs...

Code: Select all

<?php
   require_once("funkcje/swift_mailer_v3.3.3/Swift.php");
    require_once "funkcje/swift_mailer_v3.3.3/Swift/Connection/SMTP.php";
    require_once "funkcje/swift_mailer_v3.3.3/Swift/Authenticator/LOGIN.php";
 
$swift = new Swift(new Swift_Connection_SMTP("bluebyte.net.pl", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS)); 
$conn->attachAuthenticator(new Swift_Authenticator_LOGIN());
$conn->setUsername("technik");
$conn->setPassword("****");
 
$swift =& new Swift($conn);
 
//Create the message
$message =& new Swift_Message("My subject", "My body");
 
$recipients =& new Swift_RecipientList();
$recipients->addTo("taisu[at].xl");
 
if($swift->batchSend($message, $recipients, "technik[at]bluebyte.net")) echo Sent;
else echo "Failed";
 
?>
If I change the authenticator to PLAIN (but as you can see only TLS connectiooons are allowed) i get smth like this

Code: Select all

 
Dec 24 12:58:32 bb-mailserv postfix/smtpd[14917]: connect from xxx.tpnet.pl[xxxx]
Dec 24 12:58:32 bb-mailserv postfix/smtpd[14917]: lost connection after RSET from xxx.tpnet.pl[xxxx]
Dec 24 12:58:32 bb-mailserv postfix/smtpd[14917]: disconnect from xxx.tpnet.pl[xxx]
 
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Problem with sending emaisl via own mailserv with TLS :-(

Post by Chris Corbyn »

Hi, are you able to translate (roughly) this into English for me by any chance? :)
The error Message wrote:Próba połšczenia nie powiodła się, ponieważ połšczona strona nie odpowiedziała poprawnie po ustalonym okresie czasu lub utworzone połšczenie nie powiodło się, ponieważ połšczony host nie odpowiedział.
The clue to the problem is in that message. I suspect the SMTP server is not expecting a connection over TLS, or on a different port number to the one you're using.
Taisa
Forum Newbie
Posts: 7
Joined: Wed Dec 24, 2008 6:14 am

Re: Problem with sending emaisl via own mailserv with TLS :-(

Post by Taisa »

Chris Corbyn wrote:Hi, are you able to translate (roughly) this into English for me by any chance? :)
The error Message wrote:Próba połšczenia nie powiodła się, ponieważ połšczona strona nie odpowiedziała poprawnie po ustalonym okresie czasu lub utworzone połšczenie nie powiodło się, ponieważ połšczony host nie odpowiedział.
The clue to the problem is in that message. I suspect the SMTP server is not expecting a connection over TLS, or on a different port number to the one you're using.
OK, I`ll try :-)

"Connection attempt has failed, because remote host didn`t respond correct after specified time or created connection timed out, because connected host didn`t respond" Short it says - connection attempt failed and that`s correct, because there`s no signs in mail.log... The problem is what kind of authentication method should I use to make it work. I can send mail using thiunderbird with enabled tls, but how to send it by swift mailer?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Problem with sending emaisl via own mailserv with TLS :-(

Post by Chris Corbyn »

Ok, good translation, this is quite common and is usually caused by firewall rules blocking the connection. It may be possible that your host do not allow connections to be made on port 465. The following a go and see if any of these combinations work:

Port 25, no encryption
Port 587, SSL
Port 587, TLS

EDIT | Just in case you're not aware, you can put the number "587" in place of Swift_Connection_SMTP::PORT_SECURE.
Taisa
Forum Newbie
Posts: 7
Joined: Wed Dec 24, 2008 6:14 am

Re: Problem with sending emaisl via own mailserv with TLS :-(

Post by Taisa »

I`m <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> :-(((It still doesn`t work.

first - without authentication

Switf message
Failed
Mailserv logs:
Dec 25 10:36:33 bb-mailserv postfix/smtpd[22656]: connect from xxx.tpnet.pl[xxxx]
Dec 25 10:36:34 bb-mailserv postfix/smtpd[22656]: NOQUEUE: reject: RCPT from xxx[xxx]: 554 5.7.1 <taisu[at]wp.pl>: Relay access denied; from=<technik[at]bluebyte.net.pl> to=<taisu[at]wp.pl> proto=ESMTP helo=<[127.0.0.1]>
Dec 25 10:36:34 bb-mailserv postfix/smtpd[22656]: lost connection after RSET from xxx.[xxxx]
Dec 25 10:36:34 bb-mailserv postfix/smtpd[22656]: disconnect from xxx.tpnet.pl[xxx]
used code:

Code: Select all

$conn =& new Swift_Connection_SMTP("bluebyte.net.pl"); 
$swift =& new Swift($conn);
 
//Create the message
$message =& new Swift_Message("My subject", "My body");
 
$recipients =& new Swift_RecipientList();
$recipients->addTo("taisu@wp.pl");
 
if($swift->batchSend($message, $recipients, "technik@bluebyte.net.pl")) echo Sent;
else echo "Failed";
then with authenticator

Swit message (simmilar, it doesn`t matter if I`ve use tls, or ssl)

Fatal error: Uncaught exception 'Swift_ConnectionException' with message 'The SMTP connection failed to start [tls://bluebyte.net.pl:465]: fsockopen returned Error Number 10060 and Error String 'Próba po?šczenia nie powiod?a si?, poniewa? po?šczona strona nie odpowiedzia?a poprawnie po ustalonym okresie czasu lub utworzone po?šczenie nie powiod?o si?, poniewa? po?šczony host nie odpowiedzia?. '' in E:\AppServ 2.4.6\www\air2\funkcje\swift_mailer_v3.3.3\Swift\Connection\SMTP.php:309 Stack trace: #0 E:\AppServ 2.4.6\www\air2\funkcje\swift_mailer_v3.3.3\Swift.php(216): Swift_Connection_SMTP->start() #1 E:\AppServ 2.4.6\www\air2\funkcje\swift_mailer_v3.3.3\Swift.php(101): Swift->connect() #2 E:\AppServ 2.4.6\www\air2\testowy2.php(6): Swift->__construct(Object(Swift_Connection_SMTP)) #3 {main} thrown in E:\AppServ 2.4.6\www\air2\funkcje\swift_mailer_v3.3.3\Swift\Connection\SMTP.php on line 309
Nothing in mailserver logs

used code:

Code: Select all

 
$conn = new Swift(new Swift_Connection_SMTP("bluebyte.net.pl", 465, Swift_Connection_SMTP::ENC_TLS));   
$conn->attachAuthenticator(new Swift_Authenticator_LOGIN());
$conn->setUsername("technik");
$conn->setPassword("xxxxx");
 
$swift =& new Swift($conn);
 
//Create the message
$message =& new Swift_Message("My subject", "My body");
 
$recipients =& new Swift_RecipientList();
$recipients->addTo("taisu@wp.pl");
 
if($swift->batchSend($message, $recipients, "technik@bluebyte.net.pl")) echo Sent;
else echo "Failed";
 
Of course I`ve changed
conn = new Swift(new Swift_Connection_SMTP("bluebyte.net.pl", 465, Swift_Connection_SMTP::ENC_TLS));
with SSL, TLS and diffrent ports as you wrote earlier. Don`t know what I`m making wrong.

and that`s how it looks, when I`ll use Thunderbird

mailserver logs
Dec 25 13:25:29 bb-mailserv postfix/smtpd[3664]: connect from xxxx.tpnet.pl[xxxx]
Dec 25 13:25:34 bb-mailserv postfix/smtpd[3664]: 55CDAE54068: client=xxxxtpnet.pl[xxxx], sasl_method=PLAIN, sasl_username=technik[at]bluebyte.net.pl
Dec 25 13:25:34 bb-mailserv postfix/cleanup[3692]: 55CDAE54068: message-id=<49537BCA.3080501[at]bluebyte.net.pl>
Dec 25 13:25:34 bb-mailserv postfix/qmgr[5467]: 55CDAE54068: from=<technik[at]bluebyte.net.pl>, size=637, nrcpt=1 (queue active)
Dec 25 13:25:34 bb-mailserv postfix/smtpd[3664]: disconnect from xxxx.tpnet.pl[xxxx]
Dec 25 13:25:34 bb-mailserv amavis[11882]: (11882-04) NOTICE: reconnecting in response to: err=2006, S1000, DBD::mysql::st execute failed: MySQL server has gone away at (eval 40) line 153, <GEN40> line 5.
Dec 25 13:25:35 bb-mailserv postfix/smtpd[3697]: connect from localhost[127.0.0.1]
Dec 25 13:25:35 bb-mailserv postfix/smtpd[3697]: EC757E5406B: client=localhost[127.0.0.1]
Dec 25 13:25:36 bb-mailserv postfix/cleanup[3692]: EC757E5406B: message-id=<49537BCA.3080501[at]bluebyte.net.pl>
Dec 25 13:25:36 bb-mailserv postfix/qmgr[5467]: EC757E5406B: from=<technik[at]bluebyte.net.pl>, size=1112, nrcpt=1 (queue active)
Dec 25 13:25:36 bb-mailserv postfix/smtpd[3697]: disconnect from localhost[127.0.0.1]
Dec 25 13:25:36 bb-mailserv amavis[11882]: (11882-04) Passed CLEAN, [xxxx] [xxxx] <technik[at]bluebyte.net.pl> -> <taisu[at]wp.pl>, Message-ID: <49537BCA.3080501[at]bluebyte.net.pl>, mail_id: Ohg6Lupn9doI, Hits: 2.683, queued_as: EC757E5406B, 1539 ms
Dec 25 13:25:36 bb-mailserv postfix/smtp[3693]: 55CDAE54068: to=<taisu[at]wp.pl>, relay=127.0.0.1[127.0.0.1]:10024, delay=1.9, delays=0.28/0.03/0.01/1.5, dsn=2.6.0, status=sent (250 2.6.0 Ok, id=11882-04, from MTA([127.0.0.1]:10025): 250 2.0.0 Ok: queued as EC757E5406B)
Dec 25 13:25:36 bb-mailserv postfix/qmgr[5467]: 55CDAE54068: removed
Dec 25 13:25:45 bb-mailserv postfix/smtp[3700]: EC757E5406B: to=<taisu[at]wp.pl>, relay=mx.wp.pl[212.77.101.4]:25, delay=9.1, delays=0.08/0.03/0.1/8.9, dsn=2.0.0, status=sent (250 ok 1230207945 qp 25977)
Dec 25 13:25:45 bb-mailserv postfix/qmgr[5467]: EC757E5406B: removed
Taisa
Forum Newbie
Posts: 7
Joined: Wed Dec 24, 2008 6:14 am

Re: Problem with sending emaisl via own mailserv with TLS :-(

Post by Taisa »

Oh man. I`ve great problem... no one is able to help me :-((
Taisa
Forum Newbie
Posts: 7
Joined: Wed Dec 24, 2008 6:14 am

Re: Problem with sending emaisl via own mailserv with TLS :-(

Post by Taisa »

I guess I have found an anserw... funny
viewtopic.php?f=52&t=79771&start=0&st=0&sk=t&sd=a
Taisa
Forum Newbie
Posts: 7
Joined: Wed Dec 24, 2008 6:14 am

Re: Problem with sending emaisl via own mailserv with TLS :-(

Post by Taisa »

OK. I`ve found solution :-) I`ve reconfigured my mailserv. Everywhere there`s a lot about TLS supoort etc, bo NO ONE don`t even mention, that there are two diffrent types TLS. If you telnet localhost/domainname 25 (on you mailserver)
and you see smth like this...

Code: Select all

 
telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 bb-mailserv.bluebyte.net.pl ESMTP Postfix (Debian/GNU)
ehlo bluebyte.net.pl
250-bb-mailserv.bluebyte.net.pl
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS <---------!!!!
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
 
it doesn`t mean that you can send mail using tls via swiftmailer, or phpmailer...
If you use thunderbird or outlook - no problem. Why?
Because "they" know how to properly connect...
Let me explain.
First client connect to mailserv (say ehlo), it see STARTTLS command, so it start encrypted connection. It connect once more, say ehlo again, and THEN our mailserv give it AUTH command...
None of used script doen`t support that method...
Now we can make it work using tls connection supported in swiftmailer and phpmailer...
We have to change (if we are able) some options in our postfix config
first of all we could....
postconf -e smtpd_tls_auth_only=no
allow on encrypted authorization
or...
postconf -e smtpd_tls_security_level = encrypt
enable tls connections on port 587
postconf -e smtpd_tls_wrappermode = yes
enable ssl connections on port 465
You could also set "smtpd_tls_security_level = may" to that TLS encryption is offered but it's not mandatory (so called opportunistic TLS).
postconf -e smtpd_tls_security_level = may
et voila It works :-)
Post Reply