Web apps and SMTPSecureSocket

I read much about sending mail messages with SMTPSecureSocket in web apps. Most solutions are using classes or complex mechanisms… for a contact form I want to use simpler approach by putting anything into the send button’s action event:

Dim em As New EmailMessage
(…)

Dim sss As New SMTPSecureSocket
sss.Address = smtp.colporana.com
sss.Secure = true
sss.ConnectionType = SMTPSecureSocket.TLSv12
sss.SMTPConnectionMode = SMTPSecureSocket.ModeSSLTLS
sss.Port = 25
sss.UserName = “xxx”
sss.Password = “xxx”

sss.Messages.Append(em)
sss.SendMail()

If SocketSendMail.LastErrorCode <> 0 AND SocketSendMail.LastErrorCode <> 102 Then WError.Show
(…)

As SMTP account I use the one of the server where the web app runs on (no Gmail or third party services).

Is this working the way I intend or are there any glitches or issues that could raising up when not using a separate class?

Carsten

You should rather make sss a property of the WebPage or Session, to avoid the SMTPSecureSocket to turn pumpkin because the event is over.

sss = New SMTPSecureSocket

Instead of dim.

Port 25 is usually not secure. Are you sure that’s the correct port? Are you sure you need Secure?

Thanks for the note, I’ll do so. Think Session is better choice, since the page changes after clicking at that button.

I thought that events are kept alive as long as there are tasks to do?

@Tim Hare : Yes, the port is correct; I’m not the server guy, so can’t say why that port was chosen. But I think that it has to do with some (outdated) server-sided tools. At least, it works. :slight_smile:

Port 25 is the standard mail service port. It’s just not usually configured as secure. That’s more typically ports 465 and 587.

In my experience, never assume so if it is not explicitly mentioned in the LR. Since the socket is asynchronous, it will not hold the event until finished anyway.