Solved

Send an e-mail via VBScript

Posted on 2010-11-11
6
581 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now