Solved

Need help with an email script

Posted on 2013-10-22
6
112 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now