Cannot send email via MailGun on Xojo Cloud

Hey there, I have an application that I am hosting in Xojo Cloud and one of the issues I’ve run into is that the Mailgun SMTP connection only works locally but doesn’t work from the Cloud instance. I am connecting to the Mailgun SMTP server using the built in SMTPSecureSocket class:

[code]Public Sub SendEmail(toAddress as string, subject as string, message as string, attachment as FolderItem = nil)
Dim email As New EmailMessage
email.FromAddress = “system@example.com
email.Subject = subject
email.BodyPlainText = message
email.AddRecipient(toAddress)

if SMTP = nil then SMTP = new SMTPSecureSocket

SMTP.Address = kSMTPServer
SMTP.Port = kSMTPPort
SMTP.Username = kSMTPUsername
SMTP.Password = kSMTPPassword
SMTP.Messages.Append(email)
SMTP.SendMail

if SMTP.LastErrorCode <> 0 then
App.Log("ERROR: SMTP error: " + Str(SMTP.LastErrorCode))
end if
End Sub[/code]

No error is returned in SMTP.LastErrorCode. There is no logged connection attempt in Mailgun’s log either, meaning that the connection is being blocked before it reaches Mailgun’s server.

This works perfectly locally, but not on Cloud. Is there any kind of outgoing connection blocking on the Cloud server or something else that I need to do special for this type of thing to work correctly?

Are you opening the firewall port?

https://documentation.xojo.com/index.php/FirewallPort

Ah okay, thanks for the hint. I think this is indeed what I needed, hadn’t thought to look for it for some reason.

I think this is the first time I see a service with a firewall that blocks remote ports (Outgoing). I think it is very good option to have.