Solved

Send an e-mail via VBScript

Posted on 2010-11-11
6
585 Views
Last Modified: 2012-05-10
I am a .Net programmer so I am struggling with this one. For testing purposes of a larger project I am trying to send an email when an html page loads. Later i will add reports to go out as an attachment. I keep on getting an ActiveX error. Can someone explain to me why this won't work and how I can get it to work on my local machine? Eventually it will go on a server as a scheduled task.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Untitled Page</title>
<script type="text/vbscript">
function sendEmail()
      Set objMailer = CreateObject("SMTPsvg.Mailer")
      'Email File
      objMailer.AddRecipient "JimmyDeuce" , "Jimmydeuce@notimportant.com"
      objMailer.AddBcc "Jimbo" , "Jimbo@notimportant.com"
      objMailer.FromName = "Kiosk Report"
      objMailer.FromAddress = "me@somewhere.com"
      objMailer.RemoteHost = "localhost"
      objMailer.ReturnReceipt = false
      objMailer.ConfirmRead = false
      objMailer.Subject = "Subject Here"
      objMailer.BodyText = "Hello World"
      objMailer.ClearAttachments
      objMailer.SendMail            
      Set objMailer = Nothing      
      window.setTimeout "exitApp()",3000       
end function
    </script>
</head>
<body onload="sendEmail()">

</body>
</html>
0
Comment
Question by:JimmyDeuce
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:jcott28
ID: 34114160
Do you have the smtp  service setup on the workstation?

You've got to specify a smart host or an smtp server.
0
 

Author Comment

by:JimmyDeuce
ID: 34114183
I belive so. I have Outlook installed.
0
 
LVL 5

Expert Comment

by:jcott28
ID: 34114191
If you setup a smart host on your local machine, you can try this method too:

Set objMailer = CreateObject("CDO.Message")
objMailer.To = "Jimmydeuce@notimportant.com"
objMailer.From = "me@somewhere.com"
objMailer.Subject = "Subject Here"
objMailer.Textbody = "Hello World"
objMailer.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMailer.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
        "127.0.0.1"
objMailer.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMailer.Configuration.Fields.Update
objMailer.Send
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:JimmyDeuce
ID: 34114192
i thought localhost was teh smart host in this case.
0
 
LVL 5

Expert Comment

by:jcott28
ID: 34114204
Outlook is not an smtp service.

Check this out:

http://msdn.microsoft.com/en-us/library/8b83ac7t.aspx
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 34114620
Not sure if this will work, because there may be security restrictions on calling this from a web page, but this attempts to automate Outlook.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Untitled Page</title>
<script type="text/vbscript">
function sendEmail() 
      Set objMailerApp = CreateObject("Outlook.Application")
      Set objMailer = objMailerApp.CreateItem(0)
      'Email File
      objMailer.To "Jimmydeuce@notimportant.com"
      objMailer.Bcc "Jimbo@notimportant.com"
      objMailer.Subject = "Subject Here"
      objMailer.Body = "Hello World"
      objMailer.Send
      Set objMailer = Nothing      
      Set objMailerApp = Nothing      
      window.setTimeout "exitApp()",3000       
end function 
    </script>
</head>
<body onload="sendEmail()">

</body>
</html> 

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question