Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send email through VBS script

I am trying to send an email via VBS but I keep getting errors. I want it to send a email as simple as possible.

Does not work, with this error:

        Set objEmail = CreateObject("CDO.Message")
        objEmail.From = "[email protected]"
        objEmail.To = "[email protected]"
        objEmail.Subject = "thisisasubject" 
        objEmail.Textbody = "Here is the message"
        objEmail.Send

Error:

line: 6

Char: 1 error: The "sendusing"configuration value is invalid. 80040220

like image 465
Tim Avatar asked Feb 23 '14 19:02

Tim


People also ask

How to Send email through VBScript?

Just insert your desired parameters such as smtp mail server address, credentials, email addresses and content of the email with attachment within the provided variables inside the script and execute the script to start sending email instantaneously.

What is VB scripting language?

VBScript is an interpreted script language from Microsoft that is a subset of its Visual Basic programming language designed for interpretation by Microsoft's Internet Explorer (IE) web browser.


2 Answers

Set emailObj      = CreateObject("CDO.Message")

emailObj.From     = "[email protected]"
emailObj.To       = "[email protected]"

emailObj.Subject  = "Test CDO"
emailObj.TextBody = "Test CDO"

Set emailConfig = emailObj.Configuration

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing")    = 2  
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1  
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl")      = true 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")    = "YourUserName"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")    = "Password1"

emailConfig.Fields.Update

emailObj.Send

If err.number = 0 then Msgbox "Done"
like image 72
David Candy Avatar answered Sep 21 '22 19:09

David Candy


Set MyEmail=CreateObject("CDO.Message")

Const cdoBasic=0 'Do not Authenticate
Const cdoAuth=1 'Basic Authentication

MyEmail.Subject = "Subject"
MyEmail.From    = "<[email protected]>"
MyEmail.To      = "<[email protected]>"
MyEmail.TextBody= "TEST MAIL"

MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2

'SMTP Server
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.server.com"

'SMTP Port
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25


MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

'Your UserID on the SMTP server
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"

'Your password on the SMTP server
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"


'Use SSL for the connection (False or True)
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

MyEmail.Configuration.Fields.Update
MyEmail.Send

Set MyEmail=nothing
like image 25
Saba Avatar answered Sep 21 '22 19:09

Saba