Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

June 15, 2005 12:00 AM

How can I send an email message from within a VBScript script?

Windows IT Pro
InstantDoc ID #46746
Rating: (16)

A. If you have Microsoft IIS with SMTP installed on a server, you can use the following code to send a basic email message from within a script:

Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = "Subject"
objMessage.Sender = "administrator@savilltech.com"
objMessage.To = "batman@savilltech.com"
objMessage.TextBody = "Your identity is compromised."
objMessage.Send
(Substitute your own email information and message text.) You can insert this code into any script that requires a message to be sent.

Related Content:

ARTICLE TOOLS

Comments
  • frida
    4 years ago
    Jun 17, 2008

    hi tribina,

    Is it possible to use your code on active web-page which i have? Im looking at a script which automatically extracts certain fields out of my website and automatically puts it into outlook mail ready to send, in contrast to the current procedure i follow which involves copy- pasting each time to compose an email. Id realy appreciate any help on this.

  • Anonymous User
    7 years ago
    Jun 22, 2005

    For another option, which doesn't require the use of IIS, try Blat. (http://www.blat.net) It works extremely well, and is very simple to configure.

  • Carlos
    7 years ago
    Jun 21, 2005

    Here's my submission of a sub that does the same but without the need for IIS or a server. It does require NetCat, http://m.nu/program/util/netcat/netcat.html.
    Sub SendMsg(sMsg, sSub, sFrom, sTo, sSMTP)
    smtpMsgs = Array("HELO ", "MAIL FROM:<" & sFrom & ">", "RCPT TO:<" & sTo & ">", "DATA", "TO:"& sTo, "SUBJECT:" & sSub , sMsg, ".", "quit")
    Set oWS = WScript.CreateObject("WScript.Shell")
    Set oExec = oWS.Exec("nc.exe -w 5 " & sSMTP & " 25")
    WScript.Sleep 1000
    for each smtpMsg in smtpMsgs
    oExec.StdIn.Write smtpMsg & VbCrLf
    WScript.sleep 100
    next
    end Sub

    SendMsg "Hi From SendMsg", "Test", "foo@foo.com", "foobar@foobar.com", "smtpserver"

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.