dcsimg
Results 1 to 17 of 17
  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    595

    Send email using Gmail

    Hello
    I tested tons of codes trying to send an email via Gmail but all of them are not working.
    I think that Google security policy became more stringent on this side.
    Is there a working code, please?
    thank you all

  2. #2
    Frenzied Member
    Join Date
    Dec 2008
    Posts
    1,118

    Re: Send email using Gmail

    Hi,
    You should get the Moderators to move this to the VB6 Forum

    This may help you with gmail's nanny over kill -
    try going to your gmail inbox – click on settings at top right (the little cog wheel) – select Settings in the dropdown – select Accounts and Import – click on Other Google account settings – click Security – and enable ‘Access for less secure apps’. This setting is normally enabled for personal gmail accounts it may be disabled and or the setting may be unavailable/ unchangeable for business users.

    HTH,
    Rob

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    595

    Re: Send email using Gmail

    Thanks Bobbles
    In fact I have already done that step but no success.

  4. #4
    Frenzied Member
    Join Date
    Dec 2008
    Posts
    1,118

    Re: Send email using Gmail

    This is worth downloading -
    http://www.vbforums.com/showthread.p...ent-using-smtp

    There are some attempts to use gmail, not successful in the latter years, but still worth getting.
    Plus the author appears interested in getting it to work with gmail (again)

    Rob

  5. #5
    Frenzied Member
    Join Date
    Dec 2008
    Posts
    1,118

    Re: Send email using Gmail

    I have another suggestion.
    In this codebank forum http://www.vbforums.com/forumdisplay...-6-and-earlier
    Top'ish right'ish, there is an option 'Search Forum'
    Type gmail in there and do the search.
    It returns quite a few codebank threads that include discussion about using gmail.

    If you solve it, don't forget to share it with us,
    Rob

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    595

    Re: Send email using Gmail

    Quote Originally Posted by Bobbles View Post
    This is worth downloading -
    http://www.vbforums.com/showthread.p...ent-using-smtp

    There are some attempts to use gmail, not successful in the latter years, but still worth getting.
    Plus the author appears interested in getting it to work with gmail (again)

    Rob
    Thanks sir for the link
    The sample is working but only if we modify the security standards in Gmail

  7. #7
    Frenzied Member
    Join Date
    Dec 2008
    Posts
    1,118

    Re: Send email using Gmail

    Quote Originally Posted by samer22 View Post
    Thanks sir for the link
    The sample is working but only if we modify the security standards in Gmail
    Good news, you are doing better than most
    I am sure there are members that would be keen to use gmail.
    Could you post/attach your solution ?

    Rob

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,919

    Re: Send email using Gmail


  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    595

    Re: Send email using Gmail

    The sample that I got it working is in the link you provided

    http://www.vbforums.com/showthread.p...ent-using-smtp
    However to get it work, there are some security configurations as you have mentioned in #2 which makes the code not too praticable.
    thanks

  10. #10
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,453

    Re: Send email using Gmail

    I just happened onto this thread this morning...do you have it solved?
    I have been using Gmail to send birthday reminders to myself and others for many years now...all within a VB6 program, which is run every morning from my Task Scheduler. I'm running it on a Win 7 machine.

    If you don't have this solved, let me know and I can post my code.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    595

    Re: Send email using Gmail

    SamOscarBrown
    Im still looking for that code.
    Please post it.
    thanks a lot

  12. #12
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,453

    Re: Send email using Gmail

    I have this in a Module:

    Code:
    Option Explicit
    
    Dim msgA As Object 'Define the CDO
    
    
    Public Function GmailSend(xUsername, xPassword, xMailTo, xSubject, xMainText)
    'Where xUsername is your gmail account, xPassword is your password to that gmail account,
    'xMailTo is someone's email address, xSubject is self explanatory, and xMainText is what you want in the body
        Set msgA = CreateObject("CDO.Message") 'set the CDO to refer as.
        msgA.to = xMailTo 'get targeted mail from command
        msgA.Subject = xSubject 'get subject from command
        msgA.HTMLBody = xMainText 'Main Text - You may use HTML tags here, for example <BR> to immitate "VBCRLF" (start new line) etc.
        msgA.From = "mail@mail.com"  'The from part, make sure its syntax template is a valid mail one, user@domain.com, or something.
    ' HTMLBODY is a STRING, do not try to link a multilined textbox to it without using the ''replace'' function for 'VBCRLf' with '<BR>' (example later)
            'Notice, i simplified it, however, you may use more values depending on your needs, such as:
        '.Bcc = "mail@mail.com" ' - BCC..
        msgA.Cc = "anybody@anyemailserver.com"  'to whomever you want to send a CC copy..also can send BCC copy
        '
        '.CreateMHTMLBody ("www.mywebsite.com/index.html) 'send an entire webpage from a site
        '.CreateMHTMLBody ("c:\program files\download.htm) 'Send an entire webpage from your PC
        '.AddAttachment ("c:\myfile.zip") 'Send a file from your pc (notice uploading may take a while depending on your connection)
           'Gmail Username (from which mail will be sent)
        msgA.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = xUsername
        'Gmail Password
        msgA.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = xPassword
            'Mail Server address.
        msgA.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
            'To set SMTP over the network = 2
            'To set Local SMTP = 1
        msgA.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            'Type of Authenthication
        '0 - None
        '1 - Base 64 encoded (Normal)
        '2 - NTLM
        msgA.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
            'Port
        msgA.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
            'Send using SSL True\False
        msgA.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
            'Update values of the SMTP configuration
        msgA.Configuration.Fields.Update
            'Send it.
    '        debug.print xUsername & " " & xPassword & " " & xMailTo & " " & xSubject & " " & xMainText
        msgA.Send  'Need to add this
            ' On error ... (using on error resume next is over rated, realy.)
        GmailSend = Err.Number
        If Err.Number <> 0 Then MsgBox "Mail Error: " & Err.Description
     End Function

  13. #13
    Frenzied Member
    Join Date
    Dec 2008
    Posts
    1,118

    Re: Send email using Gmail

    Sam,
    I was trying (unsuccessfully) to encourage the OP to clarify how he got the code (from the link I posted) to work. Which he did not do.

    So I appreciate you chipping in with some code,
    Rob

  14. #14
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,453

    Re: Send email using Gmail

    Yeah Bobbles,....sorry I GAVE OP the code...I couldn't figure out if the was completely lost or not...thought so. So, instead of trying to EXPLAIN, I just 'gave'. Sometimes it is not worth all the time to walk someone through a process. And in difference to dilettante, I don't think he has to worry about the OP taking over his job.

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    595

    Re: Send email using Gmail

    SamOscarBrown
    thanks a lot.
    in fact that 's the code I'm using.
    However this needs to turn on access for less secure apps for gmail account, otherwise it won't work

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    595

    Re: Send email using Gmail

    Bobbles
    I just did what it appears on the image in the link you posted.

    Name:  gmail.png
Views: 108
Size:  11.8 KB

    But to get it working I was obliged to go here and turn on access for less secure apps .
    https://www.google.com/settings/security/lesssecureapps
    Attached Images Attached Images  

  17. #17
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,604

    Re: Send email using Gmail

    gmail does have an API that can be used to create more secure apps
    https://developers.google.com/gmail/...ckstart/dotnet
    there is no examples for vb6 or vba, but possibly the code could be ported, though i would probably just not use gmail at all for this type of application
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width