vbscript - Using VBS to call text file to populate to field in email -
vbscript - Using VBS to call text file to populate to field in email -
i creating script placed on servers run without user interaction send email when criteria met. have criteria script running, want create script easy deploy , modify each individual server.
i trying create script create phone call text file populate field in email. text file have email addresses placed 1 per line (i putting semicolon on end of addresses since know multiple addresses separated semicolons)
i have tried number of different variations on calling script , either error on line, or makes through script , error no recipients defined. here script below:
`set objfso = createobject("scripting.filesystemobject") set objdictionary = createobject("scripting.dictionary") set objfileemailaddresses = objfso.opentextfile("emailaddresses.txt", 1) set objwmiservice = getobject("winmgmts:{impersonationlevel=impersonate}!\\.\root\cimv2") set wshshell = wscript.createobject("wscript.shell") strcomputername = wshshell.expandenvironmentstrings("%computername%") servicesarray = split (objfileemailaddresses.readall, vbnewline) each strservice in servicesarray objdictionary.add strservice, strservice next set objemail = createobject("cdo.message") objemail.from = "email@server.com" objemail.to = objfileemailaddresses objemail.configuration.fields.item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objemail.configuration.fields.item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp address" objemail.configuration.fields.item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objemail.configuration.fields.update objemail.fields.item("urn:schemas:mailheader:x-msmail-priority") = "high" objemail.fields.item("urn:schemas:mailheader:x-priority") = 2 objemail.fields.item("urn:schemas:httpmail:importance") = 2 objemail.fields.update objemail.subject = "primary server " & ucase(strcomputername) & " rebooting now" objemail.textbody ="the primary server " & ucase(strcomputername) & " scheduled reboot @ time. server offline in less 1 minute. .... " objemail.send objfileemailaddresses.close()`
the to
field of objemail
object should string containing 1 or more e-mail addresses. you're assigning textstream object (objfileemailaddresses
) it.
you said e-mail addresses end semicolon? seek instead:
' open text file containing of e-mail addresses... set objfileemailaddresses = objfso.opentextfile("emailaddresses.txt", 1) ' read entire file. replace newlines nil single ' string of semicolon-separated e-mail addresses... straddresses = replace(objfileemailaddresses.readall, vbcrlf, "") ' assign string e-mail object... objemail.to = straddresses
you can rid of dictionary
object. unless you're afraid may have same e-mail addresses listed more once, in case may need utilize one.
email vbscript
Comments
Post a Comment