Solved

Need help with an email script

Posted on 2013-10-22
6
116 Views
Last Modified: 2014-10-29
Hello,
I'm trying to create a email vb script that I can call by arguments from other scripts to send out different email responses.  Here is my code so far but need  a little help in getting it functional.  Thanks for any help you can provide.

Set myMail=CreateObject("CDO.Message")
Const ForReading = 1

set args = WScript.Arguments
' Parse args
select case args.Count
case 0
    sVariable = args(0) myMail.Subject=("Test environment is now shutting down")
case 1
    sVariable = args(1) myMail.Subject=("Test environment is now online")
end select


myMail.From="email address"
myMail.To="email address"
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="server name"
'Server port
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25 
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing




'To call for for example, arg1, then cscript //nologo emailscript1.vbs  ARG1

Open in new window

0
Comment
Question by:WeberTech
  • 2
  • 2
6 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39593235
I use this for a reference http://www.paulsadowski.com/wsh/cdo.htm 

It looks like you are missing a the body.

myMail.TextBody = "This is some sample message text."

or

txtEmailBody="This is some sample message text."

myMail.TextBody =txtEmailBody


Are you having other issues?
0
 
LVL 1

Author Comment

by:WeberTech
ID: 39593630
Hi Padas,
Yes, I'm getting a error message.  It says, Error on Line 8, Char 25, Error: Expected end of statement.  Did I miss something?
0
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 39594321
I think you want to change

case 0
    sVariable = args(0) myMail.Subject=("Test environment is now shutting down")
case 1
    sVariable = args(1) myMail.Subject=("Test environment is now online")
end select

Open in new window

to
case 0
  myMail.Subject=("Test environment is now shutting down")
case 1
   myMail.Subject=("Test environment is now online")
end select

Open in new window

0
 
LVL 1

Author Comment

by:WeberTech
ID: 39594608
Yeah, I took it in a whole different direction and getting better results now.  Seems to be working now.

dim args(1)
dim myMail
Set myMail=CreateObject("CDO.Message")
myMail.Subject = WScript.Arguments.Item(0) & " environment is now " & WScript.Arguments.Item(1)
WScript.echo "first arg: " & WScript.Arguments.Item(0)

WScript.echo "second arg: " & WScript.Arguments.Item(1)

WScript.echo "subject: " & myMail.Subject

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question