VBScript to send emails not working, error code 0x80040217? -


i have following vb script works fine when sending email gmail account. however, i'd send emails corporate account uses google apps account. i'm not sure if should chance smtp server in code, if so; should be?

const cdosendusingpickup = 1 'send message using local smtp service pickup directory.  const cdosendusingport = 2 'send message using network (smtp on network).   const cdoanonymous = 0 'do not authenticate const cdobasic = 1 'basic (clear-text) authentication const cdontlm = 2 'ntlm  set objmessage = createobject("cdo.message")  objmessage.subject = "this test!"  objmessage.from = "dummy1@somecorp.com"  objmessage.to = "dummy2@somecorp.com"  'objmessage.textbody = "this sample message text.." & vbcrlf & "it sent using smtp authentication , ssl." objmessage.htmlbody = "<h1>this sample message in html.</h1><br/><h2>just test html elements if they're working or not.</h2>"  '==this section provides configuration information remote smtp server.  objmessage.configuration.fields.item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2   'name or ip of remote smtp server objmessage.configuration.fields.item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"  'type of authentication, none, basic (base64 encoded), ntlm objmessage.configuration.fields.item _ ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdobasic  'your userid on smtp server objmessage.configuration.fields.item _ ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "dummy1@somecorp.com"  'your password on smtp server objmessage.configuration.fields.item _ ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"  'server port  objmessage.configuration.fields.item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465   'use ssl connection (false or true) objmessage.configuration.fields.item _ ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true  'connection timeout in seconds (the maximum time cdo try establish connection smtp server) objmessage.configuration.fields.item _ ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60  objmessage.configuration.fields.update  '==end remote smtp server configuration section==  objmessage.send msgbox "done:)" 

gmail users can access account on official website or using first-party or third-party apps , services instead. first party app instance google's official gmail app android, while thunderbird , mail client app of windows 8 third-party apps.

google announced in april 2014 improve sign-in security of services , affect application sending usernames , passwords company.

the company suggested switch oauth 2.0 did not enforce until now.

if open new less secure apps page under security settings on google, notice google has disabled access default.

note: see page if not using google apps or have enabled two-factor authentication account.

you can flip switch here enable less secure applications again access regained.

enter image description here

try vbscript works me, on side, , tell me if encountered problems or not.

emailsubject = "sending email cdo" emailbody = "this body of message sent via" & vbcrlf & _         "a cdo.message object using smtp authentication ,with port 465."  const emailfrom = "self@gmail.com" const emailfromname = "my own name" const emailto = "someone@destination.com" const smtpserver = "smtp.gmail.com" const smtplogon = "self@gmail.com" const smtppassword = "gmailpassword" const smtpssl = true const smtpport = 465  const cdosendusingpickup = 1    'send message using local smtp service pickup directory. const cdosendusingport = 2  'send message using smtp on tcp/ip networking.  const cdoanonymous = 0  ' no authentication const cdobasic = 1  ' basic clear text authentication const cdontlm = 2   ' ntlm, microsoft proprietary authentication  ' first, create message  set objmessage = createobject("cdo.message") objmessage.subject = emailsubject objmessage.from = """" & emailfromname & """ <" & emailfrom & ">" objmessage.to = emailto objmessage.textbody = emailbody  ' second, configure server  objmessage.configuration.fields.item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2  objmessage.configuration.fields.item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpserver  objmessage.configuration.fields.item _ ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdobasic  objmessage.configuration.fields.item _ ("http://schemas.microsoft.com/cdo/configuration/sendusername") = smtplogon  objmessage.configuration.fields.item _ ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = smtppassword  objmessage.configuration.fields.item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = smtpport  objmessage.configuration.fields.item _ ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = smtpssl  objmessage.configuration.fields.item _ ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60  objmessage.configuration.fields.update 'now send message! on error resume next objmessage.send  if err.number <> 0     msgbox err.description,16,"error sending mail" else      msgbox "mail sent !",64,"information" end if 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -