Solved

Creating and sending an Appointment item with VB script

Posted on 2004-08-25
6
514 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
  • 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ms access #TYPE! error on report when no data 4 52
Determine Range to Select 5 34
How to debug this code 7 51
Copy a row 12 53
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

746 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