?
Solved

Need help with an email script

Posted on 2013-10-22
6
Medium Priority
?
119 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 53

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 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 2000 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

752 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