Web App SendMail Fails in Build but works on Run

Screen grab of code below:

This is very similar to another topic for API v1 – Sending Mail via Web App API1

I have no idea why this works just fine with multiple email addresses on Run but when I upload it onto a DigitalOcean server (Linux, my own build) it fails.

The change I made is I activated an SSL cert on my server and somehow that changed everything.

Do I need to open up a port or change to special settings for an SSL-certed box?

Var ms As New SMTPSecureSocket
Var mm As New EmailMessage
Var mt As String

Var mmb As String
Var mme As String
mmb = “123456”
mme = “[YOUR EMAIL]”

Try

// Configure the SMTP socket
ms.Secure = True
ms.Address = “mail.privateemail.com
ms.Port = 465
//ms.Port = 25
//ms.Port = 587
ms.Username = “no_reply@scamjam.net”
ms.Password = “[PASSWORD]”
ms.SSLConnectionType = SMTPSecureSocket.SSLConnectionTypes.SSLv23
ms.SMTPConnectionType = SMTPSecureSocket.SMTPConnectionTypes.STARTTLS

// Populate the email message
mm.FromAddress = “no_reply@scamjam.net”
mm.AddRecipient(mme)
mm.Subject = “Confirm E-mail With Code”
mt = “” + mmb + “ is your code. This email is a send-only account and is not checked for responses.”
mm.BodyHTML = mt
mm.Headers.AddHeader(“X-Mailer”, “SMTP Send Code”)

// Add attachments if needed
// Var attachFile As New EmailAttachment
// attachFile.LoadFromFile(yourFolderItem)
// mm.Attachments.Add(attachFile)

// Add the message to the socket and send
ms.Messages.Add(mm)
ms.SendMail

br_email.Caption = “Code Sent”
Timer1.Period = 3000
Timer1.RunMode = WebTimer.RunModes.Single

Catch error_sendout As RuntimeException

End Try

Much appreciation for any insight.

NameCheap supplies the following article for their PrivateEmail – https://www.namecheap.com/support/knowledgebase/article.aspx/10715/93/email-encryption-what-is-ssl-and-tls/

I have tried just about every combo of socket security that I could.

Have you confirmed that you can send from your host via another application? Some hosts block outgoing SMTP, in which case you’d need to use a REST api rather than SMTP.

1 Like

Your smtpsecuresocket is going out of scope for one thing…

3 Likes

Your ms variable needs to be a property of a module, app, window or web page to make it last long enough.

Sending emails is asynchronous and you basically cancel it at the end of the method when the local variable goes out of scope.

This is probably the answer. I’ll try this today and see what happens.

I tried that and it works on Run but fails silently on deployment.

:thinking:

The process is to click the Register button and then input your email address, click the button to receive a code sent to your email, check and verify the code, then click the button to verify. The app is in development and does nothing more than this step at this current time.

I got it to work on my in-house server (xyztext.com)

And the same exact code, for some strange reason, will not work on a DigitalOcean droplet (scamjam.net)

Both are the same configs under LifeBoat and in NameCheap DNS, so the difference lies between the droplet and my homebrew box that I am going to have to sort.

Very strange bug, indeed.

@Tim_Parnell also checked on this and confirmed that @Christian_Wheel is correct.

I created a process to confirm / troubleshoot:

  1. In the App, create a variable that is a string. Call it something easy like z1.
  2. In the App, create a method with an easy name like zp, in Parameters have a String like “datatext” to receive string data, and the code is merely adding two EndOfLine to z1 and then adding the passed text to z1.
  3. In a window, place a TextArea and Button - and the Button’s action code is for TextArea.Text = App.z1 — and there is your error and process messages polling.

For anyone considering DigitalOcean… you will need access to a way of authenticating users / email addresses that does not involve SMTP.

Hope this helps, and THANK YOU to all who helped me resolve this!
Having homebrew servers can help developers sort these issues, I highly recommend it.

For what it’s worth, I have written an open-source drop-in SMTPSecureSocket replacement for sending EmailMessage via the Mailjet HTTP REST API. This would be a way to use almost entirely the same code to send an EmailMessage from a DigitalOcean droplet.

1 Like