SMTPsecureSocket subclass - how to access Error event ?


I have an SMTPsecureSocket, subclassed as emailSocketClass, and provided as a property (myMailSocket) as part of the app object.

If an error occurs during an email send, I would like the error event of the socket to advise the user.

I therefore do this in the app.init method, called at

myMailSocket = new emailSocketClass
AddHandler myMailSocket.Error addressOf mailError

where mailError is a method in app

The line addHandler myMailSocket.Error fails with a “EmailSocketClass has no member named .Error” - which is not what the docs say about SMTPsecureSocket.

If I change this to
AddHandler myMailSocket.writeError addressOf mailError
it fails with a syntax error.

What is wrong here ?

Tony Barry

What is the method definition for mailError?

As shown on the AddHandler page, it ought to be this:

Sub mailError(sender As SMTPSecureSocket)

Hi Paul,

Many thanks for the quick reply.

The method definition for mailError is

Sub mailError(source as emailSocketClass)

which is a subclass of SMTPsecureSocket.

I also have tried the explicit

Sub mailError(source as SMTPsecureSocket)

but this fares no better.

Tony Barry

More info.
If I add an emailSocketClass instance to a window, by drag and dropping the class on the window, the new socket thus created does have the event “.Error” available to it.

So the class is OK. But it’s not allowed in the App object it would seem.

Any thoughts here ? I have a ridiculously simple project which shows this behaviour …

Xojo 2015r3.1 / MacOS 10.9.5

Tony Barry

Are you missing a comma here?

AddHandler myMailSocket.Error, addressOf mailError

Good catch. Otherwise, it looks like you’re referring to a method, Error, that takes an argument, AddressOf mailError, and returns an value to AddHandler. There is no Error method or event so defined.

Hi Paul,

Thanks again.

Yes I was missing a comma, which cured the syntax error.

Autocomplete does not offer the expected Error event:-
AddHandler myMailSocket.Error <- this does not autocomplete

biut it does compile when I write
AddHandler myMailSocket.writeError, addressOf mailError

I am setting up the mailSocket to intentionally fail (by putting in a wrong address for the mail server) and no emails are sent when I do this. If I enter the correct address it does send (and I receive the email sent at the other end).

I am confident the email link can work, but I cannot get any indication of error from the event.

Tony Barry

Try ServerError instead of Error. Error is for non-specific errors. A bad address should be caught in ServerError. (Note: I didn’t test this before replying.)

There is no writeError at

Hi Tim,

Unfortunately, ServerError does not autocomplete; and the addHandler line fails with a typeMismatch error.

Hi Michel,

WriteError may not be in the docs but it is the only thing close to Error which does autocomplete.
Error is in the docs but the event does not fire under any circumstances I can generate.

Despite this may I say thank you to all those who have replied. I am able to place a SMPTsecureSocket on a window and use that (and it does have a usable Error event, which does fire). While I would like to use events in code, they don’t seem to work here.

If there are any hardy souls who wish to see a very simple demo project of the issue, I would be pleased to post it to a web page for your viewing pleasure.

Tony Barry

Trust the docs over autocomplete. It is still being perfected in the new IDE.

Thank you for the heads-up Tim. The new docs (“Dev Center”) are less usable than the old, but at least they exist and are being updated.

Tony Barry

FWIW, I instantiated an smtpsecuresocket in code and attached a method to Error with AddHandler, and it fires just fine.

Make sure the signature of your method matches the signature of the event, plus an initial parameter of type SMTPSecureSocket.

Hi Tim,
I am sure that it works. I very much doubt that Xojo Inc would send it out with such a basic part being Dead.
My issue is that after having done what the instructions say, I have non-functionality.

In your case, did you subclass the SMPTsecureSocket before instantiating it in code ? And did you explicitly call the super’s constructor ? I have tried both and neither seem to vary my results.

Ah well. I am sure that the answer is out there. Many thanks for your thoughts, Tim. I will persevere.

Tony Barry

Yes, I did. I’d be willing to look at a demo project.

Hi Tim,

Many thanks for your support. Muchly appreciated.

The zipped project can be downloaded from

It is 8kB in size. Compiled under RB2015r3.1, run on MacOS 10.9.5

Tony Barry

Hi Tim,

The README in the App class Notes describes the function of the project.

Once again, thanks for any insights you can share.

Tony Barry

[quote=235828:@Tony Barry]WriteError may not be in the docs but it is the only thing close to Error which does autocomplete.
Error is in the docs but the event does not fire under any circumstances I can generate.[/quote]

Autocomplete is a function of the IDE which while convenient, is not the ultimate reference. And there are several places where it does not autocomplete (for instance System). You should always refer to the doc, and enter manually if it does not autocomplete.

I hate to break it to you, but when you type SMTPSecureSocket in Developer.Xojo.Com, the page that displays is in fact from the old LR in an iframe :

<iframe id="docwiki" src=""></iframe>

Hi Michel,

Thank you for your reply. Yes, I would gather that Autocomplete is less perfect that the docs … but it is more perfect than I am.

Hence my reliance on a fallible tool.

Regarding the old versus the new developer docs; well, I am just glad for any insight. No need to be reluctant to tell me the truth - I would rather know the truth and be found ignorant, than be ignorant squared.

Tony Barry

The socket seems to be a little inconsistent with regard to the error event. By commenting out the lines

  app.TextMedsMailSocket.port = 465
  app.TextMedsMailSocket.ConnectionType = SMTPSecureSocket.SSLv23 //was 23
  app.TextMedsMailSocket.Secure = true
  app.TextMedsMailSocket.SMTPConnectionMode = SMTPSecureSocket.ModeSTARTTLS

in various combinations, I get the error or not, and I get the immediate error result or not. Maybe a Xojo engineer could give you more information.