Send Email with attachment

Not sure if anybody else has witnessed this but evidently Google no longer lets external apps sign in directly to Gmail anymore. I saw a posting that this started late May. I had a windows program I created that creates a pdf and emails to a list of email addresses. The program creates the file but will no longer email. Does anyone know if this can still be done in Gmail by changing some settings? Or can it be done with a Yahoo or Outlook account. Below is the code I had that used to work.

lblStatus.Value = "Sending email"
MailSocket.Address = "smtp.gmail.com"
MailSocket.Port = 587
MailSocket.ConnectionType = SMTPSecureSocket.TLSv1
MailSocket.SMTPConnectionMode = SMTPSecureSocket.ModeSSLTLS
MailSocket.Secure = True
MailSocket.SMTPConnectionMode=1
MailSocket.UserName = my gmail address
MailSocket.Password = my password
email.FromAddress = my gmail address
email.Subject = "Schedule"
email.BodyPlainText = "Attached is the schedule!"

for i = 0 to lstEmailAddress.listcount - 1
  email.AddRecipient(lstEmailAddress.list(i))
next

fileemail.LoadFromFile(f)

If fileemail.Name.Right(4) = ".pdf" Then
  fileemail.MIMEType = "application/pdf"
End If

email.Attachments.Add(fileemail)

MailSocket.Messages.AddRow(email)
MailSocket.SendMail

Your “less secure app” and gmail

If you use an app to pick up mail from or send to your gmail account, then you may wish to read on. If your app is what Google terms a “less secure app” for accessing gmail, and indeed if you do download your gmail from Google using it, then you must already have logged onto your gmail account and enabled “allow less secure apps” You will also have received warnings from Google that as of 30th May this will no longer be allowed.

So, what to do? Google would like us to implement something called OAUTH2 in our apps, but myself I haven’t felt inclined to do so. But what I have found is that one can continue with an existing app by using something called an app-specific password. I’m doing this and it seems to work. Here’s how.

Firstly, you’ll need to logon to your gmail account, and under “Manage account”, choose “Security”. Then, choose to enable Two-step-verification, or 2SV as they call it (also known as 2FA, or “two factor authentication”). This will take you through a sequence where you signup e.g. your smart phone to receive a code to enter, in addition to your password, at your sign in to Google from a device you’ve not signed in from previously.

Having done this, return to your Security page, and in the part on “Signing in to Google”, you’ll see the section about “App Passwords”. Expand that section next. Where you see “Select device” in that section, choose your device type. Then, where it says “Select App”, choose “Other” and enter some name for your app. Now you can click “Generate”. This will put up a pane with a password in large type that you need to copy (with ctrl/cmd-c or similar) to the clipboard.

Now switch to your app and open its Preferences. Choose your gmail account, highlight the password field, and paste (with ctrl/cmd-v or similar) the password you copied above into the password field. Then click Save.

That’s it.

Oh, and this procedure should work for any so-called “less secure app” you may be using to download your gmail.

If your app is a simple one in sucxh as Xojo, just paste the password in to your code:

4 Likes

Thanks Tim, I’ll give it a try.

@TimStreater thank you for the detailed explanation. It works great!

Glad to hear it. I was mightily relieved when I had that explained to me on Usenet (uk.comp.sys.mac) and found that all google is doing, really, is giving you a password other than your gmail login password, to use in your second-rate app. Hah!

Great tutorial, worked like a charm. Thanks!

One Caveat to the App Password to keep in mind is ALL App passwords are reset if the the Account password gets changed.

4 Likes