How to create an SMTP alert when a script is finished.

Hello,
I wrote a VBScript that copies about 125GB of data. I was wondering how I can get the script to send an SMTP message to my epager when the script is finished. Also if there are any errors, i would like to be alerted.

Thanks!
Drew_MoraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jbarbataCommented:
Hi Drew,

Here is a function I use frequently... You'll need to replace "mail.example.com" with your own mail server address - It's in like line 27.

'Setup Message Variables
 msgSndr = "sender@example.com"
 msgRcvr = "receiver@example.com"
 msgSubj = "Message Subject"
 msgBoby = "Message body"

'Call the sendmail routine!
Call sendmail(msgSndr, msgRcvr, msgSubj, msgBoby)


Sub sendmail(msgSndr, msgRcvr, msgSubj, msgBoby)
'###################################
'### EMAIL NOTIFICATION ROUTINE ###
'###################################
Dim iMsg, iConf, Flds, strHTML

Const cdoSendUsingPort = 2

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

Set Flds = iConf.Fields

With Flds
 .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.example.com"
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
 .Update
End With

With iMsg
 Set .Configuration = iConf
 .To = msgRcvr
 .From = msgSndr
 .Subject = msgSubj
 .TextBody = msgBoby
 .Send
End With

 Set iMsg = Nothing
 Set iConf = Nothing
 Set Flds = Nothing
End Sub
0
Drew_MoraAuthor Commented:
Here is my code. I ran the code and got an error @ line 28: Failed to connect to the server.

On line 27 where I put the email domain, do I have to do anything else?

'Setup Message Variables
 msgSndr = "amora@umcaz.edu"
 msgRcvr = "amora@umcaz.edu"
 msgRcvr = "drew.mora@Gmail.com"
 msgSubj = "File-Copy-Complete"
 msgBoby = "The Files have been copied"

'Call the sendmail routine!
Call sendmail(msgSndr, msgRcvr, msgSubj, msgBoby)


Sub sendmail(msgSndr, msgRcvr, msgSubj, msgBoby)
'###################################
'### EMAIL NOTIFICATION ROUTINE ###
'###################################
Dim iMsg, iConf, Flds, strHTML

Const cdoSendUsingPort = 2

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

Set Flds = iConf.Fields

With Flds
 .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "umcaz.edu"
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
 .Update
End With

With iMsg
 Set .Configuration = iConf
 .To = msgRcvr
 .From = msgSndr
 .Subject = msgSubj
 .TextBody = msgBoby
 .Send
End With

 Set iMsg = Nothing
 Set iConf = Nothing
 Set Flds = Nothing
End Sub
0
Drew_MoraAuthor Commented:
Now I am getting:

Error: The transport failed to connect to the server.
Line: 38

Here is my code:
'#####################################################################################
'Setup Message Variables
 msgSndr = "amora@umcaz.edu"
 msgRcvr = "amora@umcaz.edu"
 msgRcvr = "drew.mora@Gmail.com"
 msgSubj = "File-Copy-Complete"
 msgBoby = "The Files have been copied"

'Call the sendmail routine!
Call sendmail(msgSndr, msgRcvr, msgSubj, msgBoby)


Sub sendmail(msgSndr, msgRcvr, msgSubj, msgBoby)
'###################################
'### EMAIL NOTIFICATION ROUTINE ###
'###################################
Dim iMsg, iConf, Flds, strHTML

Const cdoSendUsingPort = 2

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

Set Flds = iConf.Fields

With Flds
 .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "amora@umcaz.edu"
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
 .Update
End With

With iMsg
 Set .Configuration = iConf
 .To = msgRcvr
 .From = msgSndr
 .Subject = msgSubj
 .TextBody = msgBoby
 .Send
End With

 Set iMsg = Nothing
 Set iConf = Nothing
 Set Flds = Nothing
End Sub
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

jbarbataCommented:
Great Drew, y

Your almost there... just need to point that message at  a mail server that you can relay through.

In:
  .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "amora@umcaz.edu"

"amora@umcaz.edu" - should be so something like "mail.umcaz.edu" or "smtp.umcaz.edu" or even simply the ip address of your mail server. try: "smtp1.umcaz.edu" or "198.60.159.41" - I got these results back from your domain:

# nslookup
> set type=mx
> umcaz.edu

Non-authoritative answer:
umcaz.edu       preference = 10, mail exchanger = smtp2.umcaz.edu
umcaz.edu       preference = 10, mail exchanger = smtp1.umcaz.edu

Authoritative answers can be found from:
smtp2.umcaz.edu internet address = 198.60.159.41
smtp1.umcaz.edu internet address = 198.60.159.40
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Drew_MoraAuthor Commented:
Ohhhhh cool, I misunderstood, sorry for that. I understand now! Thanks mucho!

It works like a charm!
0
Drew_MoraAuthor Commented:
One other question......How do I send to more than 1 Rcvr? I need 3 people to be notified.
0
jbarbataCommented:
That’s awesome!

Here are three diferent ways to send multipal messages:

1.) Just change the receiver variable and call the mail function again: (not recomended)
  msgRcvr = "new.address@Gmail.com" 're-write receiver variable.
  Call sendmail(msgSndr, msgRcvr, msgSubj, msgBoby)

2.) Simply add multipal receiver addresses: (recomended)
   msgRcvr = "new.address@Gmail.com; new.address2@Gmail.com; new.address3@Gmail.com"

3.) You could change the function to include a CC. field:

With iMsg
 Set .Configuration = iConf
 .To = msgRcvr
 .Cc = "cc.address1@somedomain.com; cc.address2@somedomain.com"  
 .From = msgSndr
 .Subject = msgSubj
 .TextBody = msgBoby
 .Send
End With

Good luck!
 
0
Drew_MoraAuthor Commented:
Great Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.