Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
Shwetha is currently offline  Shwetha
Messages: 36
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 #45981 is a reply to message #45980] Sun, 07 February 2016 07:08 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11143
Registered: November 2005
Ultimate Member
Do you mean this

https://en.wikipedia.org/wiki/STARTTLS

?

This is not supported yet, but should not be that hard to do, except that I do not have any SMTP server to support this to debug it.

(If you just need secure SMTP over TLS, on standard port 465, you can activate it by Smtp::SSL)

Mirek

[Updated on: Sun, 07 February 2016 07:09]

Report message to a moderator

Re: How to use TLS over SMTP [message #48040 is a reply to message #45981] Fri, 12 May 2017 17:37 Go to previous messageGo to next message
Tom1
Messages: 378
Registered: March 2007
Senior Member
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 #48043 is a reply to message #48040] Fri, 12 May 2017 21:28 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 369
Registered: August 2007
Location: Turkey
Senior Member
Hello Tom and Mirek,
I added STARTTLS support to SMTP package and updated its doc accordingly. (It's a few lines of additional code, actually. Smile )

Could you please test it. I only had the chance to test it with gmail (for now) but it works.
I can also add STARTTLS support to POP3 class, if you need it, or think that it would be a worthy addition.

See below message for updated package:
http://www.ultimatepp.org/forums/index.php?t=msg&th=9559 &goto=48098&#msg_48098

Regards.

Oblivion.

[Updated on: Wed, 17 May 2017 08:41]

Report message to a moderator

Re: How to use TLS over SMTP [message #48045 is a reply to message #45980] Fri, 12 May 2017 22:34 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 369
Registered: August 2007
Location: Turkey
Senior Member
I made a silly mistake.
Setters should be:

Smtp&      SSL(bool b = true)                                 { ssl = b; if(b) starttls = !b; return *this; }
Smtp&      StartTLS(bool b = true)                            { starttls = b; if(b) ssl = !b; return *this; }


Regards,
Oblivion,

[Updated on: Wed, 17 May 2017 08:41]

Report message to a moderator

Re: How to use TLS over SMTP [message #48046 is a reply to message #48045] Fri, 12 May 2017 22:42 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 471
Registered: September 2012
Location: Poland, Kraków
Senior Member
Hello,

The feature ticket must be for that improvement - #1719 Smile Thanks!

Sincerely,
Klugier


Ultimate++ - one framework to rule them all.
Re: How to use TLS over SMTP [message #48049 is a reply to message #48045] Sat, 13 May 2017 10:13 Go to previous messageGo to next message
Tom1
Messages: 378
Registered: March 2007
Senior Member
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 #48050 is a reply to message #48049] Sat, 13 May 2017 11:14 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 369
Registered: August 2007
Location: Turkey
Senior Member
Hello Tom,

You are right. Removing "else" works well also on gmail. It seems that a new EHLO/HELO is not required by every server. Gmail does not require it, at least.
I've read the RFC 3207 some time ago, Guess I should've re-read.

Anyways, please find attached the updated patch. It should work properly now.
Yet new tests would be appreciated. Smile

See below message for updated package:
http://www.ultimatepp.org/forums/index.php?t=msg&th=9559 &goto=48098&#msg_48098

Regards,

Oblivion

[Updated on: Wed, 17 May 2017 08:40]

Report message to a moderator

Re: How to use TLS over SMTP [message #48060 is a reply to message #48050] Sat, 13 May 2017 20:55 Go to previous messageGo to next message
Tom1
Messages: 378
Registered: March 2007
Senior Member
Hi Oblivion,

Works like a charm. Tested on Win10 Professional 32 bit and Linux Mint 18.1 64 bit.

Thanks a lot for your work on this.

Hope this gets merged to Upp tree soon enough. Smile

Best regards,

Tom

[Updated on: Sat, 13 May 2017 20:56]

Report message to a moderator

Re: How to use TLS over SMTP [message #48083 is a reply to message #48060] Mon, 15 May 2017 09:22 Go to previous messageGo to next message
Tom1
Messages: 378
Registered: March 2007
Senior Member
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 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 369
Registered: August 2007
Location: Turkey
Senior Member
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. Smile

I'll publish a new patch within a couple of days.

Thanks for testing.

Regards,

Oblivion.


[Updated on: Mon, 15 May 2017 10:39]

Report message to a moderator

Re: How to use TLS over SMTP [message #48085 is a reply to message #48084] Mon, 15 May 2017 11:06 Go to previous messageGo to next message
Tom1
Messages: 378
Registered: March 2007
Senior Member
Hi Oblivion,

Sounds good. Smile

Best regards,

Tom
Re: How to use TLS over SMTP [message #48098 is a reply to message #48085] Tue, 16 May 2017 20:10 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 369
Registered: August 2007
Location: Turkey
Senior Member
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.) Smile
- 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. Smile

Regards,

Oblivion.
  • Attachment: SMTP.zip
    (Size: 8.94KB, Downloaded 21 times)

[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 Go to previous messageGo to next message
Tom1
Messages: 378
Registered: March 2007
Senior Member
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! Smile

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

Re: How to use TLS over SMTP [message #48102 is a reply to message #48101] Wed, 17 May 2017 10:36 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 369
Registered: August 2007
Location: Turkey
Senior Member
Quote:
The following line compiles with "warning C4804: '<': unsafe use of type 'bool' in operation":

if(!ext.Find("starttls") < 0)


Ah, that's a typo (a remnant, actually). Smile
Thank you very much for feedback!


Regards.

Oblivion

[Updated on: Wed, 17 May 2017 10:37]

Report message to a moderator

Re: How to use TLS over SMTP [message #48458 is a reply to message #48102] Wed, 05 July 2017 12:15 Go to previous message
mirek is currently offline  mirek
Messages: 11143
Registered: November 2005
Ultimate Member
It is now in the trunk. In the process, I have also removed that ugly "log_message_body" parameters.
Previous Topic: Send/receive files with SCP and launch commands with SSH
Next Topic: Code before Thread.Run() nor executed
Goto Forum:
  


Current Time: Fri Oct 20 12:49:04 CEST 2017

Total time taken to generate the page: 0.01296 seconds