Results 1 to 10 of 10

Thread: Sending Email with Gmail? Or something else?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2005
    Posts
    558

    Sending Email with Gmail? Or something else?

    Hey people. Anybody have a sample project sending an Email using Gmail now that Google has done away with the "less secure" application stuff?

    Reason I ask... I have an on-line server through TMD Hosting. They have a Windows Server client which I've been using to send out PDF files to some customers. My VB app makes an email, adds the PDF file and sends it to the Email server. Sometimes they go through. Sometimes they don't. After a fair bit of testing, any email with an attachment only has about a 50% chance of going through depending on the day. The problem is absolutely with TMD but they have zero interest in fixing this problem.

    So I need a reliable email solution. Preferably cheap and/or free. Something that lets me send an email with a file attachment maybe 20 or 30 a month.

    Any ideas?
    Last edited by Darkbob; Jan 31st, 2023 at 10:26 AM.

  2. #2
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    1,294

    Lightbulb Re: Sending Email with Gmail? Or something else?

    As far as I know you need to have 2-factor authentication enabled in your Google account in order to generate an app password. As an alternative you could use Yahoo's SMTP server: "smtp.mail.yahoo.com" (also with a generated app password) since it doesn't require you to enable 2-factor authentication.

    Code:
    Private Function SendMail(sTo As String, sSubject As String, sMailBody As String, Optional sError As String, Optional sAttachment As String) As Boolean
    Dim cdoMsg As CDO.Message, cdoConf As CDO.Configuration
    On Error GoTo ErrHandler
        Set cdoMsg = New CDO.Message: Set cdoConf = New CDO.Configuration
        With cdoConf
            .Fields(cdoSendUsingMethod) = cdoSendUsingPort
            .Fields(cdoSMTPServer) = "smtp.gmail.com"
            .Fields(cdoSMTPServerPort) = 465
            .Fields(cdoSMTPUseSSL) = True
            .Fields(cdoSMTPAuthenticate) = cdoBasic
            .Fields(cdoSendUserName) = "username@gmail.com"
            .Fields(cdoSendPassword) = "generated_app_password"
            .Fields(cdoSMTPConnectionTimeout) = 30
            .Fields.Update
        End With
        With cdoMsg
            Set .Configuration = cdoConf
            .From = "Sender address"
            .To = sTo
            .Subject = sSubject
            .TextBody = sMailBody
            If Len(sAttachment) > 0 Then .AddAttachment sAttachment
            .Send
        End With
        SendMail = True
        Exit Function
    ErrHandler:
        sError = Err.Number & ": " & Err.Description
    End Function

  3. #3
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,468

    Re: Sending Email with Gmail? Or something else?

    See:
    https://www.vbforums.com/showthread....4-with-TLS-1-3
    It uses 2 Factor authentication.

    On the receiving end, Gmail will simply drop any email with an attachment that it considers executable. A PDF falls in that category, as it can have executable components. The way around that is to disguise it, and that requires something to be done outside of the control of Gmail. Renaming the file is not adequate, as they will simply examine the file format. What I have done in the past is to encode the file with Base64, and require the recipient to decode it.

    From the command line:
    -----------------------------Encode---------------------------
    certutil -encode setup.exe tmp.b64 && findstr /v /c:- tmp.b64 > data.b64
    -----------------------------Decode---------------------------
    certutil -decode data.b64 setup.exe

    J.A. Coutts

  4. #4
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,094

    Re: Sending Email with Gmail? Or something else?

    Gmail can decode base64 easily if they decide to be nasty. Zipping with password with the password sent along the message body or OOB is inpenetrable to anti-vir solutions at least until AI start understanding actual natural language. . . Oh, wait!

  5. #5
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,468

    Re: Sending Email with Gmail? Or something else?

    Quote Originally Posted by wqweto View Post
    Gmail can decode base64 easily if they decide to be nasty. Zipping with password with the password sent along the message body or OOB is inpenetrable to anti-vir solutions at least until AI start understanding actual natural language. . . Oh, wait!
    Zipping did not work for me. Gmail was still able to tell what it was and dropped it. I even placed it on a server zipped, but the recipient was using Google Chrome and it was blocked. It is conceivable that Gmail could recognize the Base64 format in the future, but that would mean they would have to decode it to tell what it was. When and if that happens, we will be left with no alternative but to encrypt it. Then it would appear as just random data.

    J.A. Coutts

  6. #6
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,094

    Re: Sending Email with Gmail? Or something else?

    Zipping with password is another way of saying “to encrypt a file” but with regular programs like 7-zip people know how to use.

  7. #7
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,126

    Re: Sending Email with Gmail? Or something else?

    I use gMail all the time (every day a couple of my programs send ME (and cc's others) birthday notifications, but without attachments). (Yes, I had to set up the 2-factor authentication--I have THOSE instructions if needed). I was unaware that gMail would stop pdf's....why not create and send your 'information' in a different format...maybe as simple as a text file, or maybe MS Word (I don't know what your PDFs look like or contain); or as suggested, try to zip the pdf first?
    Sam I am (as well as Confused at times).

  8. #8
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,447

    Re: Sending Email with Gmail? Or something else?

    My main Gmail account happily receives emails with PDF attachments. If PDFs agrees being blocked I wonder if it is down to the specific contents of any given PDF.

  9. #9
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,391

    Re: Sending Email with Gmail? Or something else?

    Some .pdf files may contain active content (JavaScript, etc.) or links to sites that may be flagged as dodgy, and that may cause them to be removed.

  10. #10
    Member
    Join Date
    May 2018
    Posts
    51

    Re: Sending Email with Gmail? Or something else?

    Quote Originally Posted by Darkbob View Post
    Hey people. Anybody have a sample project sending an Email using Gmail now that Google has done away with the "less secure" application stuff?
    Any ideas?
    If your app was relying on the 'enable less secure apps' setting there is an easy workaround. You just need to enable 2FA on the Gmail account then setup an app password. In your VB6 app just use the newly generated app password in place of the account password. Once setup it continues to work as before without further 2FA being needed. My main production VB6 app still uses Gmail accounts this way.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width