Solved

Send an e-mail via VBScript

Posted on 2010-11-11
6
586 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Find out what you should include to make the best professional email signature for your organization.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

740 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