|
|
Home » U++ Library support » U++ MT-multithreading and servers » How to use TLS over SMTP
How to use TLS over SMTP [message #45980] |
Sat, 06 February 2016 12:55  |
Shwetha
Messages: 39 Registered: August 2011
|
Member |
|
|
Hello,
I am using SMTP for email communication.
Here I got a prob to use TLS over SMTP, could I get any support to overcome this ??
|
|
|
|
Re: How to use TLS over SMTP [message #48040 is a reply to message #45981] |
Fri, 12 May 2017 17:37   |
Tom1
Messages: 1301 Registered: March 2007
|
Ultimate Contributor |
|
|
Hi,
My ISP does not support SMTP over SSL (SMTPS on port 465) but instead they support STARTTLS on port 587 in addition to plain connection. It would certainly be useful to be able to use STARTTLS. Any plans to add STARTTLS to Smtp:: ?
(Actually I just tried first time the Smtp:: and found it very useful with many usage scenarios! Very nice!)
Best regards,
Tom
|
|
|
|
|
|
Re: How to use TLS over SMTP [message #48049 is a reply to message #48045] |
Sat, 13 May 2017 10:13   |
Tom1
Messages: 1301 Registered: March 2007
|
Ultimate Contributor |
|
|
Hi,
Wow, that was fast Oblivion! Thanks!!
However, sending with STARTTLS failed with an error:
503 5.5.1 Error: send HELO/EHLO first
when processing:
String ans = SendRecv("AUTH LOGIN\r\n");
I fixed it by removing the 'else' after initializing STARTTLS and allowing new HELO inside STARTTLS mode. I think I read somewhere that after going into STARTTLS makes server drop all prior information and therefore requires starting over with new HELO:
throw Exc("Server does not provide SMTP service information.");
}
//else
SendRecvOK("HELO " + org + "\r\n");
if(!IsNull(auth_user)) {
String ans = SendRecv("AUTH LOGIN\r\n");
...
Can you confirm if this is correct? It seems to work fine on my ISP's SMTP server.
Thanks and best regards,
Tom
|
|
|
|
|
Re: How to use TLS over SMTP [message #48083 is a reply to message #48060] |
Mon, 15 May 2017 09:22   |
Tom1
Messages: 1301 Registered: March 2007
|
Ultimate Contributor |
|
|
Hi Oblivion,
It seems we need one more change in bool Smtp::Send(const String& msg_):
...
// receive initial message & send hello
do{
ans=SendRecv(Null);
}while(ans[3]=='-');
String org;
int pos = sender.Find('@');
...
That is, adding the do-while loop and checking the answer for the dash. My ISP (or rather their Postfix server) occasionally sends the greeting with a dash (220-...) indicating a multi-line response. and then on the next line will follow the final greeting. If that is not picked out from the queue, the EHLO will fail. After fixing the code as above, the trace from Smtp:: will show desired behavior with Postfix server:
SMTP send:
Reply: 220-relay.myisp.com ESMTP Postfix
SMTP send:
Reply: 220 relay.myisp.com ESMTP Postfix
SMTP send: EHLO mydomain.com
...
Best regards,
Tom
|
|
|
Re: How to use TLS over SMTP [message #48084 is a reply to message #48083] |
Mon, 15 May 2017 10:34   |
Oblivion
Messages: 1202 Registered: August 2007
|
Senior Contributor |
|
|
Hello Tom,
Quote:
That is, adding the do-while loop and checking the answer for the dash. My ISP (or rather their Postfix server) occasionally sends the greeting with a dash (220-...) indicating a multi-line response. and then on the next line will follow the final greeting. If that is not picked out from the queue, the EHLO will fail. After fixing the code as above, the trace from Smtp:: will show desired behavior with Postfix server:
So, If I understand it correctly, there's a problem with the original SendRecv() code. It doesn't handle multiline replies?
That's easy to pach.
Here's what I'll do: Instead of workarounds I'll rewrite the SendRecv() so that it can support multiline message, and reply codes automatically.
Then I'll refactor the whole login process. 
I'll publish a new patch within a couple of days.
Thanks for testing.
Regards,
Oblivion.
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Mon, 15 May 2017 10:39] Report message to a moderator
|
|
|
|
Re: How to use TLS over SMTP [message #48098 is a reply to message #48085] |
Tue, 16 May 2017 20:10   |
Oblivion
Messages: 1202 Registered: August 2007
|
Senior Contributor |
|
|
Hello Tom,
I made some modifications on SMTP:
- STARTTLS is working fine.
- Now it can handle every valid multiline response automatically and properly.
- Now the EHLO is sent first and on failure it will fall back to HELO.
- put proper pieces into place (Made certain parts into methods.) 
- Added proper smtp service extension support.
- SMTP class is now internally very flexible. It is possible to add extensions easily when needed (e.g. in future, or on request.)
- Removed manual timeout check (CheckFail()) and went U++ way, using TcpSocket::GetLine(), and TcpSocket::PutAll().
Also I have the code tested on several different configurations . All seems good.
Yet any further testing, and bug reports are appreciated. 
Regards,
Oblivion.
-
Attachment: SMTP.zip
(Size: 8.94KB, Downloaded 266 times)
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Fri, 19 May 2017 07:28] Report message to a moderator
|
|
|
Re: How to use TLS over SMTP [message #48101 is a reply to message #48098] |
Wed, 17 May 2017 10:05   |
Tom1
Messages: 1301 Registered: March 2007
|
Ultimate Contributor |
|
|
Hi Oblivion,
The following line compiles with "warning C4804: '<': unsafe use of type 'bool' in operation":
if(!ext.Find("starttls") < 0)
I guess it should be (?):
if(ext.Find("starttls") < 0)
Other than that, it works just beautifully. I tested against two servers. One supported unauthenticated access on plain, SSL/TLS and STARTTLS. The other supported authenticated STARTTLS only. All OK! 
Guess it's time to get this in Core/SMTP now.
Thank you very much!
Best regards,
Tom
[Updated on: Wed, 17 May 2017 10:07] Report message to a moderator
|
|
|
|
|
Goto Forum:
Current Time: Fri Apr 25 22:59:52 CEST 2025
Total time taken to generate the page: 0.02340 seconds
|
|
|