Sendgrid API and SMTPSecureSocket

I have used Sendgrid as my SMTP server for many years in my desktop app. I used a username/password combination.

Recently, Sendgrid required us to all change to its API version. I simply can’t make it work using SMTPSecureSocket.

emailSender is set up as a SMTPSecureSocket property of the app in the IDE.

Here is my code for app.Open event:

emailSender = new SMTPSecureSocket
emailSender.address = ""
emailSender.port = 465
EemailSender.username = "apikey"
emailSender.password = "SG.myObfuscatedAPIcode" 
emailSender.SSLEnabled = True
emailSender.ConnectionType = SMTPSecureSocket.TLSv1
emailSender.SMTPConnectionMode = SMTPSecureSocket.ModeSSLTLS

And the code when I send the email:

Dim e as new EmailMessage
e.subject= textfield5.text
e.bodyHTML = textfield7.text
e.FromAddress = ""
app.emailSender.messages.addrow e

Pretty standard stuff, I would have thought.

Using the same Sendgrid API credentials, I can send emails using MBSCurl plugin, but not using SMTPSecureSocket.

I have also tried ports 25 and 587. I have checked that I don’t have firewalls active. I have made sure the API has “Send email” permissions.

Am I doing something wrong, or is SMTPSecureSocket a bit hit-and-miss?

Try either TLSv12 (1.2 instead of 1.0) or SSLv23 (which will negotiate with the server to get the best connection).

I tried TLSv12 and SSLv23, and also ports 25 and 587 with no success.

Again, MBSCurl in the same app with the same credentials works fine. SMTPSecureSocket is causing me grief. :man_shrugging:

I had the same problem after changing the Sendgrid credentials. Switched to Chilkat and everything was okay.

That’s a shame.

Has anyone implemented SendGrid SMTP using their API, and Xojo’s SMTPSecureSocket?