Simple email VB Script

Hi,

I have an email script I was using at previous company.  Now I want to incorporate something similiar at different company.  However I can't get it to work.  So instead of duplicating it, I was wondering if there is some very, very, very basic email script that I can use to validate whether or not I have the 'email server' correctly.  Idea would be to successfully email myself by executing it.  Then I can modify the more complex one that passes in variables etc.  The erors on VB are cryptic to me and can't tell what the issue is.

Here's my current code:

'%ENV_NAME% Variable passed into the script
strLocation1 = Wscript.Arguments.Item(0)

'%EMAILSVR% Variable passed into the script
strLocation2 = Wscript.Arguments.Item(1)

'%EMAIL_TO% Variable passed into the script
strLocation3 = Wscript.Arguments.Item(2)

'%LOGDIR% Variable passed into the script
'strLocation4 = Wscript.Arguments.Item(3)

'%LOGFILENAME% Variable passed into the script
'strLocation5 = Wscript.Arguments.Item(4)


strTo = "" & strLocation3 & ""
Set objfso = CreateObject("Scripting.FileSystemObject")

strSubject = "WARNING!! - Another Hyperion maintenance is processing on " & strLocation1 & ""
strBody = "Unable to execute Hyperion maintenance process on " & strLocation1 & ".  There is another process currently running.  Please try again later or when the other process is finished." 
'strAttachFile = strLocation4 & "" & strLocation5 & ""

EMail "Admin@Company.com", strTo, strSubject, strBody,"" & strLocation2 & "" ,strAttachFile

Sub EMail(sourceAddr,destAddr,subjectText,textBody,SMTPserver)
         Set objEmail = CreateObject("CDO.Message")
         With objEmail
                 .From = sourceAddr
                 .To = destAddr
                 .Subject = subjectText
                 .TextBody = textBody
				 '.AddAttachment strAttachFile
                 .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
                 .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "" &strLocation2 & ""
                 .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
                 .Configuration.Fields.Update
                 .Send
         End With
End Sub

Open in new window



Thanks for all help.  Always tricky when trying to get email working for some reason.
elwayisgodAsked:
Who is Participating?
 
NVITCommented:
Looks like you're calling the strAttachFile but it's missing from the Sub

Also, you have:
&strLocation2 &

Open in new window


Also, your Sub has SMTPserver but isn't using it.
0
 
Steve KnightIT ConsultancyCommented:
I have a couple here if wanted of mine, search "email" on the page.

http://scripts.dragon-it.co.uk/links/batch-monitor-ping-email

You can also just send it manually using telnet.  For Windows 7+ you normally have to go into add an extra feature "Telnet client" in the control panel but aside from that just type (and no backspacing):

telnet x.x.x.x 25

(now the mail server will respond with it's banner.  if it just hangs try pressing Return.  If that is no good it will probably time out and maybe not responding or firewalled so you can't connect.

Now type these following each line by return, you can't correct any mistakes.  If you make one press return and type another line or start again!

Steve

helo mypc
mail from: myaddress@mydomain.com
rcpt to: theiraddress@theiraddress.com
rcpt to: theiraddress2@theiraddress.com
data
From: Appears on the from line
To: Appears on the to line
Subject: Subject line

Open in new window


Now enter a blank to start the message and end it with a single .

Now this is the message body.
etc.
.
quit

Open in new window


Sounds quite complicated but do it a few times and you can soon check an SMTP server without the need for any scripts or programs.

Steve
0
 
elwayisgodAuthor Commented:
That was it.  It's working now.  Thanks for help, greatly appreciated.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.