Solved

Send an e-mail via VBScript

Posted on 2010-11-11
6
592 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

752 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