Sending Mail via Web App API1

Hello all,

I wrote a console app to send email, it works perfectly. Now I’ve tried to add email to a web app written in Xojo 2019 R1.1 (API1). I can see it going out. The appropriate events fire, but it never lands in the destination. I’ve use the same properties for the Mail object and SMTPSecureSocket. So, it must be how I have it coded…

I placed the SMTPSecureSocket object onto a page. Inside a container - on the same page, a button is used to start the process. From the action event of the button, I send a command to the page that the container is on and also has the SMTP object that I had “dragged” onto the page.

Session.frmNotificationSetupPage.TestEmail( fldServerUserName.text, “Test Axcys Email”, fldeMailTestMsg.Text, fldToAddress.text,_
fldServer.Text, Val(fldPort.text) , fldServerUserName.Text, fldServerPassword.Text )

In a method on the page the following code exists:

SMTP.Address = Server
SMTP.Port = Port
SMTP.ConnectionType = SSLSocket.TLSv12
SMTP.Secure = True
SMTP.Password = UserPW
SMTP.Username = UsrName
SMTP.Messages.Append(mail)
SMTP.SendMail

I also have inside of the Container a WebTextArea where the SMPT events are displayed to show feedback.

Everything appears to work, but no emails are ever received.
Can anyone see what I’ve done wrong with this?

Thank you!
Tim

Yeah, so the problem is likely that every event that runs in a session is actually happening on a thread and when the response is done, the thread is destroyed.

I would try putting the SMTP object onto the Session class or better yet, into a dictionary in a Module where the keys are the session identifiers so you can release them later.

Thanks Greg,
But how to add the SMTP object to the Session? When I try to copy/paste no go. Same as dragging from the Library…

Tim

Make a property

Hi Greg thanks for that.

I have tried this and it still does not work. What I do is in the Container on a Form, I have a button that sends certain fields to a method in the Session. There is the property in the Session for the SMTP object and a method that holds the code to prepare and send to the SMTP object.

The code in the method executes, and via break points can see that SMTP connects etc, but no mail ever arrives.

SendMailSocket = New SMTP
Dim mail As New EmailMessage

mail.AddRecipient(“sender@domain.com” )
mail.FromAddress = “sender@domain.com”// “sender@domain.com
mail.Subject = “////> Test Email from Xojo”
mail.BodyPlainText = “Hello, World!”
// mail.Headers.AddHeader(“X-Mailer”, “Axcys AutoReporter”) // Sample header
mail.Headers.AppendHeader(“X-Mailer”, “Axcys AutoReporter”) // Sample header

SendMailSocket.Address = // your SMTP email server
SendMailSocket.Port = 587 // 995 //587 // Check your server for the property port # to use
// SendMailSocket.SSLConnectionType = MTPSecureSocket.SSLConnectionTypes.TLSv12 // TLSv1
SendMailSocket.ConnectionType = SSLSocket.TLSv12
SendMailSocket.Secure = True
SendMailSocket.Password =
SendMailSocket.Username =

SendMailSocket.Messages.Append(mail)
SendMailSocket.SendMail

I’ve removed the credentials from this post btw.

Any idea what I am doing wrong?
This is xojo 2019R1.1

Edit - Also the app closes each time this is executed. The SMTP events do not always fire either…

Thanks,
Tim

As in “experiences an exception or a crash?”

Remember, it takes time to negotiate a connection with an SMTP server.

That does not mean the problem is on the Xojo side. Do you have logs from the server side?

Have you done a test with a desktop app to see if the problem is the web app or with SMTP?