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
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.
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.
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"
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With