API2 - send email from web app

I’m still running this on my computer in the browser and trying to send an email out using the following code, but nothing is getting out. We use DNS Made Easy for SMTP services in all our desktop apps and it works fine.

dim fwp As New XojoCloud.FirewallPort(7725, XojoCloud.FirewallPort.Direction.Outgoing)
fwp.Open()
dim mail as EmailMessage
dim strMessage as String

Dim MailSocket As New SMTPSecureSocket
MailSocket.Address = “smtp1.dnsmadeeasy.com
MailSocket.Port = 7725
MailSocket.ConnectionType = SMTPSecureSocket.TLSv1
MailSocket.SMTPConnectionMode = SMTPSecureSocket.ModeSSLTLS
MailSocket.Secure = True
MailSocket.UserName = KUsername
MailSocket.Password = KPassword

mail = new EmailMessage
mail.fromAddress = cReplyEmail
mail.subject = cSubject
strMessage = cBody
mail.bodyPlainText = strMessage
mail.AddRecipient(cEmail)

MailSocket.Messages.Add mail
MailSocket.SendMail

I don’t use Xojo Cloud, but I would suggest making both fwp & mailsocket properties of the web page so they don’t go out of scope before the mail is sent.

1 Like

Wayne, I never thought of that, but that’s a good point. I noticed after it sent that the port had changed and that seemed strange. I’ll give that a shot.

Still can’t get it working. No matter what I try it doesn’t seem like the port is getting opened.

I’m running in debug mode, not XojoCloud (yet) so maybe I don’t need to specify that the port should be opened? I’m sure it won’t send the email if the port isn’t opened and that is evidently what is happening.

XojoCloud.firewallport is a property of the container that sits on the webpage where they are going to email from.

fwp = New XojoCloud.FirewallPort(7725,XojoCloud.FirewallPort.Direction.Outgoing)

fwp.Open()
if fwp.IsOpen() then

fwd.IsOpen always returns false!

FirewallPort only operates on Xojo Cloud. It has no effect locally.

1 Like

So unless I’m running in XojoCloud I should just bypass that code?

Thank Tim. I’ll give that a try.

I wanted to give an update on sending emails out from a web app.

First off, I was kind of surprised that I didn’t get more feedback from the forum, but that usually means that there’s something wrong with the code, it’s something else. And, indeed, it was.

I’m using a 3rd party mail server that we have used for a very long time. Never had an issue with using it in our desktop apps so I never suspected that it could be something related to them. And it may not be, but I’ll explain.

So in my testing I was just trying to send an email from “me” to “myself” using the same email address. Evidently, our 3rd party mail server doesn’t like that. In fact, it doesn’t even like the fact that the “mail from” address happens to be my YAHOO email address. As soon as I changed the “mail from” address to my GMAIL email address, it started working.

If anyone else is having an issue sending emails from a web app, I’m no expert, but I’d be happy to share my code with them. Just send me a private message.

1 Like