Web Email Attempt

Sign in with app passwords - Google Account Help.zip (40.7 KB)

Today, I made several new attempts with Gmail. I also have an SMTP.com account so i used it’s configuration settings to see if it would send. It still didn’t work and I use the SMTP account with my mass emailer with no problems.

So, I’m pretty sure the problem is with my code or how I’m testing it in Debug mode. Right now, my compile defaults for debugging are to compile it for Xojo Cloud using port 8080. So, it is running on 127.0.0.1:8080. I’ve tried ports 587 and 465 with no luck. Should it run normally in debug mode?

Yes, it does work in debug mode. I confirm that the correct port to send emails with GMail is 587.

Sorry, I’m a little late coming back to you. Heading into a meeting in just a few minutes. (yes, in the evening…Joy.) I will have available time to get back to you tomorrow morning.

Thank you so much!

Eureka! I finally got an email to send. However, I had to use my SMTP.com account. I never got it to work with gmail. I pasted the solution below that worked. Note that the webpage has a property called MailSocket with a Type of SMTPSecureSocket

dim mail as new EmailMessage
dim strMessage as String

MailSocket = New SMTPSecureSocket

MailSocket.Address = “send.smtp.com
MailSocket.Port = 465
MailSocket.ConnectionType = SMTPSecureSocket.TLSv12
MailSocket.SMTPConnectionMode = SMTPSecureSocket.ModeSSLTLS
MailSocket.SSLEnabled = true

MailSocket.Secure = True
MailSocket.UserName = “(Your SMTP.com Username/Email)”
MailSocket.password = “(Your SMTP Account Password)”

mail.fromAddress = “(Your Email Address)”

mail.subject = “Xojo email test”

strMessage = “sent from SMTP.com port 465”

mail.bodyPlainText = strMessage

mail.AddRecipient(“(Recipient’s email address)”)

MailSocket.Messages.Add mail
MailSocket.SendMail

1 Like

@brian_franco
the message screenshot from google said:
The setting you are looking for is not available for your account.

Markus;

did you enable 2FA on your account? if I recall, it is a prerequisite to get an application password.

Good news!

The same code (with port 587 and the application password) should work on GMail. If it does not, take a look at your MailSocket error or servererror events. It might actually tell you why the mail is not going through. You just need to create handler methods for the events. Something like this in the same method that initializes your MailSocket:

AddHandler Me.MailSocket.Error, WeakAddressOf MailSocket_ErrorHandler
AddHandler Me.MailSocket.MessageSent, WeakAddressOf MailSocket_MessageSentHandler
AddHandler Me.MailSocket.ServerError, WeakAddressOf MailSocket_ServerErrorHandler

and corresponding methods such as:

Public Sub MailSocket_ErrorHandler(MailSocket as SMTPSecureSocket, E as runtimeException)
  #Pragma Unused MailSocket
  
  System.debuglog "Socket Error: " + E.Message
    
End Sub

It can help debugging if you still want to use GMail.

Hope this helps.

LD

edit: Dont forget to remove the handlers. I do it in the closed event of a page, or when I use dialogs, in the dismissed event. In my program, I send all mail from dialogs. While recipients are handled programmatically in my application, I give the users a final say to add or remove recipients, add or remove attachments, etc. So mail is almost always sent from a webdialog.

if you sub class this SMTPSecureSocket (new class with super SMTPSecureSocket)
you have the context menu for the events :wink:

i not use 2FA, it sounds irrational to enable it for using user and password then in Xojo.
if i need sending mails via xojo i will try. thanks for the hint.

This is correct. Once I did this, I could obtain an app-specific-password from google (in your accounts Security section, IIRC), and then use that as the password for my email client logging on to gmail. This solution has worked ever since google moved to this model.

So I can send mail to gmail without needing to implement OAUTH2.

1 Like