SMTPSecureSocket Connection Test

Admittedly, those email sockets are quite unclear to me.
Anyway, I need to establish a connection to my mailserver, and after fiddling out the configuration with the help of the demo project and inspecting the port setting in Apple Mail I can send a mail via the project.
I wanted to include that in my own project but prepared a first test step with a connect and a listen command which always gives an error 107 – wrong port.

I finally included those steps in the demo project (Communication/internet/EmailSSLexample) I found that it behaves exactly the same – if I try to connect solely it will always return an error, but work if I send a mail.

As I couldn’t find anything in the documentation about that: Is it possible to create a test routine that checks if a SMTPSecureSocket can connect successfully without having to send a mail?

Connect and listen are mutually exclusive. Listen waits for a connection and connect tries to talk to a listening socket.

There are different styles of Secure SMTP. Typically some ports are setup as ssl only, while others are plain and the ssl or tls connection is started using protocol commands. So I guess it depends on what you want to check for how you might want to go about doing the test, but I think you should be able to do what you want, it just might be a little more complicated.

Unfortunately I don’t think the docs will answer your question. You may have to actually capture some traffic and see what it’s doing. Remember the connect method is inherited, so a lot of the secure stuff might happen in other parts of the code which would be opaque to us.

Are you testing Connect with an SSLSocket or SMTPSecureSocket? You shouldn’t use Connect on an SMTPSecureSocket, that’s just a vestige of the underlying framework (and probably shouldn’t be listed on the doc page).

Thanks a lot, Kevin and Tim! That explains a lot. Do you know of any means to test the validity of a SMTP(Secure)Socket connection without sending a test mail over it?

SMTP sockets are built on top of TCP, so you can use the TCP equivalents to test at the connection level. Start with a TCPSocket just to see if you can get a response. From there, you can test the secure version to see if you can get a secure response negotiated. Check the RFC for the exact challenge/response you should be getting.

It’s been a while, but I think I was able to diagnose my smtp issues with just a TCPSocket.

That said, sending a test mail is the gold standard. After the user enters his email credentials into my software, the first thing they do is click the “send a test mail” button.

Thanks again, Tim. I thought there would be a way to check the socket without sending, but apparently I was mislead by the connect method (and wondered why ConnectionEstablished never fires). This is all for a custom-tailored app for one single customer, so I think I’ll stick to your proposal and do a message send for verification before I delay the app delivery any longer.

TCP is kind of crummy in that way
The best way to test is to just try & use the socket & deal with the failures