Solved

Need help with an email script

Posted on 2013-10-22
6
115 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

770 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