Solved

Creating and sending an Appointment item with VB script

Posted on 2004-08-25
6
525 Views
Last Modified: 2008-03-10
I have a simple web page, to learn how to create and send an appointment item programmatically from a web app. I tried in javascript, but am not making too much progress. Here is what I have so far for VB:

<html>
<head>
<title>Appointment Tester</title>
<script language=vbscript>
                        
      function createapt()
      {
            Set myOlApp = CreateObject("Outlook.Application")
            Set myNameSpace = myOlApp.GetNamespace("MAPI")
            Set myOutBox = myNameSpace.GetDefaultFolder(olFolderOutbox)
            Set myitem = myOlApp.CreateItem(olAppointmentItem)
            myitem.MeetingStatus = olMeeting
            Set recip = myitem.Recipients.Add(@"rfox@myserver.com")
            recip.Type = olRequired
            recip.Resolve
            myitem.Subject = "Come To My Meeting"
            myitem.Start = #8/25/2004 1:30:00 PM#
            myitem.Duration = 5
            myitem.Send
            Set myitem = Nothing
      }
</script>
</head>
<body>
      <form ID="Form1">
            <input type="button" value="Add Appointment" onclick="createapt();" ID="Button1" NAME="Button1">
      </form>
</body>
</html>

Needless to say, it's not working or I wouldn't need you all! Can someone help?
0
Comment
Question by:RichardFox
[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 7

Accepted Solution

by:
Smallint earned 500 total points
ID: 11894200

This should work, but get ready for any kind of security warnings!!!

<html>
<head>
<title>Appointment Tester</title>
<script language=vbscript>
                   
     function createapt
          Set myOlApp = CreateObject("Outlook.Application")
          Set myNameSpace = myOlApp.GetNamespace("MAPI")
          Set myOutBox = myNameSpace.GetDefaultFolder(4)
          Set myitem = myOlApp.CreateItem(1)
          myitem.MeetingStatus = 1
          Set recip = myitem.Recipients.Add("drfox@DDmyserver.com")
          recip.Type = 1
          recip.Resolve
          myitem.Subject = "Come To My Meeting"
          myitem.Start = #8/25/2004 1:30:00 PM#
          myitem.Duration = 5
          myitem.Send
          Set myitem = Nothing
          myOlApp.quit
          Set myOlApp = nothing
     end function
     
</script>
</head>
<body>
     <form ID="Form1">
          <input type="button" value="Add Appointment" onclick="createapt" ID="Button1" NAME="Button1">
     </form>
</body>
</html>
0
 
LVL 4

Expert Comment

by:hamood
ID: 11894259
I think you can not send email through simple web page using outlook. You have to use some other technique for sending email. like you can use CDO method for sending messages

Here is sample

Sending email through Active Server Pages is not a difficult task. All you need is love. No, wait; all you need is the Collaborative Data Object, which ships with NT Option Pack 4. To make sure you have it installed, go to Start / Control Panel / Add/Remove Programs / NT Option Pack 4, and see if the SMTP Piece has been installed. If it is *not* installed, you will get an error when you try to run some of the code shown below (the error will read something like, "Invalid class string").

To create an instance of a CDO object in your ASP code, it is as simple as:

<%


Dim objCDO
Set objCDO = Server.CreateObject("CDONTS.NewMail")

%>
Now you're ready to send those emails off! CDONTS.NewMail has a few obvious, easy to use properties and methods. Let's look at some code:

<%


' This code assumes the above CDO
'instantiation code is included
objCDO.To = "mitchell@4guysfromrolla.com"
objCDO.From = "gates@microsoft.com"
objCDO.cc = "barksdale@netscape.com,jobs@apple.com"

Dim txtSubject
txtSubject = "Hello Scott! We were wanting your advice on some programming issues. Please come to Redmond at your earliest convenience for a very fat check!"

objCDO.Subject = "Attn: Scott, we need you!!"
objCDO.Body = txtSubject
objCDO.Send

%>
That's all there is to it. The properties are hopefully fairly obvious. In the above code an email is being sent to mitchelL@4guysfromrolla.com from gates@microsoft.com, and being CC'ed to barksdale@netscape.com and jobs@apple.com. The subject is simply the email message. The send method is what officially dispatches the email (don't forget this, or your email won't go anywhere!!)

CDO is fairly powerful (and bloated). You can send attachments, send to group lists, send schedules (like in Outlook).

I also have written an article which was published on 15Seconds.com dealing with uses of the CDO object. In the article (available through this URL) I discuss marketing through personalized emailing. The article outlines a good use for the CDO object.

Let's examine some of the other features of CDO. Below is a snippet of code which displays some of CDO's extraneous features:

<%

objCDO.To = "someone@xyz.com (John Doe)"
objCDO.From = "me@abc.com (Jane Doe)"
objCDO.bcc = "janedoe@aol.com" 'Blind cc
objCDO.Subject = "My Resume, per Request"
objCDO.Body = "Hello John. Here is a copy of my resume"
objCDO.Importance = 2 'High importance!
objCDO.AttachFile "\\server\jane\resume.doc","Resume.doc"
objCDO.Send 'Send off the email!

'Cleanup
Set objCDO = Nothing

%>

hamood
0
 

Author Comment

by:RichardFox
ID: 11894634
hamood, I specifically need to send an Outlook appointment item. I have already sent regular email through SMTP with no problem. But I think you have a good idea that I need CDO for this. Can you tell me something spcific to CDO and olAppointment items?

-rich
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:RichardFox
ID: 11894738
Smallint,

getting error "ActiveX component can't create obkect 'Outlook.Application'
0
 

Author Comment

by:RichardFox
ID: 11895212
Why doesn't this work?

<html>
<head>
<title>Outlook Mail Tester</title>

</head>
<body>
    <script language=vbscript>
    dim objOutlk      'Outlook
    dim objMail      'Email item
    dim strMsg
    const olMailItem = 0
    'Create a new message
          set objOutlk = createobject("Outlook.Application")
          set objMail = objOutlk.createitem(olMailItem)
          objMail.To = "rfox@esops.com"
          objMail.cc = "" 
          objMail.subject = "Any subject"
          objMail.body = "Any message"
          objMail.Send
    'Clean up
    set objMail = nothing
    set objOutlk = nothing
      </script>            
</body>
</html>
0
 
LVL 7

Expert Comment

by:Smallint
ID: 11900104

I'm agree with hammod that using outlook client objects is not the best solution for sending mail or appointments. A clean solution always will be based on server objects, but it depends on your intention and needings.

Code I posted works at least under win XP, IE 6 and Outlook XP.

If you are getting "ActiveX component can't ..." most probable cause is you have security settings of IE too high. Review this settings, specially ActiveX related settings.

0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 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