Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need help with an email script

Posted on 2013-10-22
6
Medium Priority
?
122 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 54

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 54

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

885 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