-
Dec 6th, 2017, 03:41 PM
#1
Thread Starter
Fanatic Member
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
-
Dec 6th, 2017, 11:48 PM
#2
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
-
Dec 7th, 2017, 02:54 AM
#3
Thread Starter
Fanatic Member
Re: Send email using Gmail
Thanks Bobbles
In fact I have already done that step but no success.
-
Dec 7th, 2017, 05:51 AM
#4
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
-
Dec 7th, 2017, 05:43 AM
#5
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
-
Dec 7th, 2017, 03:51 PM
#6
Thread Starter
Fanatic Member
Re: Send email using Gmail
Originally Posted by Bobbles
Thanks sir for the link
The sample is working but only if we modify the security standards in Gmail
-
Dec 7th, 2017, 08:44 PM
#7
Re: Send email using Gmail
Originally Posted by samer22
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
-
Dec 7th, 2017, 09:14 PM
#8
Re: Send email using Gmail
-
Dec 8th, 2017, 01:45 AM
#9
Thread Starter
Fanatic Member
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
-
Dec 8th, 2017, 09:40 AM
#10
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.
-
Dec 8th, 2017, 05:50 PM
#11
Thread Starter
Fanatic Member
Re: Send email using Gmail
SamOscarBrown
Im still looking for that code.
Please post it.
thanks a lot
-
Dec 8th, 2017, 09:47 PM
#12
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
-
Dec 9th, 2017, 05:27 AM
#13
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
-
Dec 9th, 2017, 06:39 AM
#14
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.
-
Dec 9th, 2017, 11:34 AM
#15
Thread Starter
Fanatic Member
-
Dec 9th, 2017, 11:27 AM
#16
Thread Starter
Fanatic Member
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
-
Dec 15th, 2017, 06:28 AM
#17
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|