All Forums >> [Scripting] >> WSH & Client Side VBScript >> VBS, email, error checking and functions Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
I have created functions for each different email message. My problem is I want to make the SMTP Server information a separate function that each email function calls.. but I can not seem to get this to work
Right now I get an error everytime I try putting the smtp information into a function, the script has about a dozen different email functions going to different people for different reason.. So I would like to cut down on the lines of code. Any ideas why this will not work? Can I not call a function from within a function? I dont recall every trying in any other script language.
Also, does anyone have any idea how I could error check if the email actually sent or not? these emails would be critical and I really need some kind of error checking to check if they sent susscefully or not.
I think that the problem you are running into has to do with the differences between local and global scopes. Basically, in your SMTP function, you are making changes to the objMessage object, but as soon as that function exits, those changes are lost - they only exist inside of that function.
To accomplish what you are wanting... being able to change the smtp server on the fly for each message, since the string used to determine the smtp server is only a string, why not draw that value from a function?
Example:
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers)
"It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
thanks for the idea, That still kind of defeats what I was trying to do by limiting the lines of code. I guess the problem is a function inside a function in this case.
Still I am up for ideas on some way to error check the email function as a whole? I keep reading that instead of useing a function I could use a sub routine, and then do an exit value check? Ill have to wait til I get back to work to test that... I dont even have a computer at home with windows on it, so that should tell you guys I am out of my element here :o