HOWTO: Windows Script Host Script for Sending E-MailID: Q197920
|
This is a simple VBScript example of how to automate sending mail through Microsoft Outlook.
This example will work in either an Active Server Pages (ASP) page or in
Windows Script Host (WSH), as long as there is a valid Outlook User
Profile available on the system. This User Profile appears in the from
field of the mails generated. It would be possible to set up a Profile that
is used solely for sending automated messages.
Use the following steps with WSH:
Save the code listed below into a file with a .vbs extension. To test,
double-click on the file in Windows Explorer.
If you are using Windows 95, you need to install Wsh.exe from the following
Web site to enable Windows Script Host:
http://msdn.microsoft.com/scriptingUse the following steps with ASP:
'Body of email message
Dim msgBody
msgBody="A mail from the Windows Script Host!"
'Call our function with recipient, message and subject
MySendMail "someone@example.microsoft.com",msgBody,"Automated Message."
Sub MySendMail(recipient,msg,subject)
Dim objSession, oInbox, colMessages, oMessage, colRecipients
Set objSession = CreateObject("MAPI.Session")
objSession.Logon "A Valid User Profile"
Set oInbox = objSession.Inbox
Set colMessages = oInbox.Messages
Set oMessage = colMessages.Add()
Set colRecipients = oMessage.Recipients
colRecipients.Add recipient
colRecipients.Resolve
oMessage.Subject = subject
oMessage.Text = msg
oMessage.Send
objSession.Logoff
Set objSession = nothing
End Sub
NOTE: If you intend to run these scripts from the context of a service, look at article Q177851 in the REFERENCES section below.
For additional information, please see the following articles in the Microsoft Knowledge Base:
Q193685 Sending E-mail from a Command Prompt Using IIS SMTP Service
Q191430 Run a WSH file from NT Scheduler
Q177851 Build a VB/Messaging Application to Run from a Service
http://premium.microsoft.com/msdn/library/techart/msdn_aspmess.htm
Additional query words:
Keywords : kbAutomation kbScript
Version : WINDOWS:1.0,3.0,95,98; winnt:4.0
Platform : WINDOWS winnt
Issue type : kbhowto
Last Reviewed: July 14, 1999