XOJO Mail: Port and Security?

Greetings - I’m writing a security application. It monitors certain hardware and maintains a log of the readings. Every midnight, it needs to email a copy of the previous 24 hour log to the department head. I am using XOJO 2017R1. It is a VERY large building that I cannot reveal at this point; I suspect that they have their own mail sever. I know that I need to find out the server name is, what port number it uses and what the security requirements are.

M y first question has to do with port number and privileges. It appears that ports 25, 110, or 587 are the ones most likely to be needed. Under SocketCore.LastErrorCode, the LR says: “you can only bind to ports less than 1024 if you have “root” privileges. A normal “Admin” user does not have root privileges.” But, under SocketCore.Port, it says: “On most operating systems, attempting to bind to a port less than 1024 causes a Error event to fire with an error number 107 unless the application is running with administrative permissions.” Which one is it, and how do insure that the application is running under the correct privileges (Mac for testing and Win for use target)?

The second question has to do with SMTPSecureSocket. This appears to be needed with Port 587. The first hurdle, here, is that I do not understand the statement: “If you use a constructor in a subclass of a SMTPSecureSocket, you must call the Super class’s constructor in your subclass’s constructor. The subclass will not work unless this is done.” The second hurdle is actually how to use it and how to deal with SSL Certificate? Is this something that has to be acquired? If so, where? Or, is there some sort of blanket certificate available for XOJO apps? Finally, where can I see an example using SMTPSecureSocket? That would really help!

Thanks
Jim Wagner
Oregon Research Electronics

You do not need special privileges to connect to a port, regardless of the port number. “Binding” to a port (AKA “listening”) is something that happens when your socket is accepting inbound connections. But your app wants to initiate an outbound connection to a mail server (and it’s the server that has to worry about binding and permissions.)

Constructor methods are a special method of a class that gets called automatically when you create an instance of the class. All Xojo socket classes do some necessary initialization work in their Constructor methods. If you override the Constructor in a subclass then you must make sure to call Super.Constructor() so that this initialization can be done.

Sub Constructor() Super.Constructor() // execute the superclass Constructor // your initialization code here End Sub

If you aren’t overriding the Constructor then you don’t need to worry about this.

Thanks, Andrew. that helps a lot. Is there somewhere I can find example code for using SMTPSecureSocket?

Jim

James Wagner
Oregon Research Electronics

Xojo/Example Projects/Communication/Internet/Email/SMTPSecureSocketExample.xojo_binary_project

Missed that. Thanks.

Maybe the example indicates, but will ask ahead, here. Can an SMTPSecureSocket be used in situations NOT requiring TLS/SSL? Or, do I need to have both the secure and insecure sockets available?

Jim Wagner
Oregon Research Electronics

See https://documentation.xojo.com/api/deprecated/deprecated_class_members/sslsocket.secure.html .

Thanks Beatrix - I had not gotten that far in the documentation, yet.

Jim

I have had problems with trying to connect an smtpsecuresocket to a non-ssl smtp server.
I had to make a test, instanciating a smtpsocket or smtpsecuresocket myself depending on the secure property.
it may be a problem from the starttls that you cannot clear.

Maybe there is something “left over” from that unsuccessful connection attempt? But, interesting. I was wondering about having to do exactly that.

Jim

@James Wagner - did you try the example in the Examples folder that @Jean-Yves Pochez mentioned? the SendDemoWindow has complete code that works really well. You can just drag the MailSocket control into your project, configure it and run it. It even gives you errors to help you troubleshoot.