• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4954
  • Last Modified:

capture send event of ActiveXObject Outlook.application in asp

I am creating an Outlook.application object in asp to allow the users to get an Outlook window, filled in with relevant details and attachments. This works okay. However, I need to capture the event caused by them pressing the Send button in the Outlook window, so I can write information about what they send to a database.

I can't work out how to capture this event within my asp code.

The code is shown below:

<html>
<head>
<title></title>
<script language=javascript>

      var myNameSpace
      var myItem
      var myRecipient = "<user@domain.com>"
      var mySubject = "test"
      var myBody = "This is a test message"
      var myOutlook = new ActiveXObject("Outlook.Application");

      // this works
      function SendMail (recipient, subject, body)
      {
          var myNameSpace = myOutlook.GetNameSpace("MAPI").CurrentUser;
          var myMailItem = myOutlook.CreateItem(0);
          
          myMailItem.Recipients.Add (recipient);
          myMailItem.Subject = (subject);
          myMailItem.Body = (body);
          myMailItem.Display(0);
          myNameSpace.Logoff;
      }

</script>
<script>
      // this doesn't work
      function myOutlook::ItemSend()
      {
             alert ("called ItemSend");
      }

      SendMail (myRecipient, mySubject, myBody)

      alert ("Finished Sending Mail");

</script>
</head>
<body>
</body>
</html>
0
sacerdoteuk
Asked:
sacerdoteuk
1 Solution
 
sacerdoteukAuthor Commented:
After a bit of playing around, I have answered my own question. The eend event is fired by the mailitem, not by the Outlook application, and I needed Send rather than ItemSend, which isn't available in VBScript.

<html>
<head>
<title></title>
<script language=javascript>

      var myRecipient = "<user@domain.com>"
      var mySubject = "test"
      var myBody = "This is a test message"
      var myOutlook = new ActiveXObject("Outlook.Application");
                var myNameSpace = myOutlook.GetNameSpace("MAPI").CurrentUser;
                var myMailItem = myOutlook.CreateItem(0);

      // creates the outlook page
      function SendMail (recipient, subject, body)
      {   
          myMailItem.Recipients.Add (recipient);
          myMailItem.Subject = (subject);
          myMailItem.Body = (body);
          myMailItem.Display(0);
          //myMailItem.Send();
          myNameSpace.Logoff;
      }
</script>
<script>
      // user has clicked send
      function myMailItem::Send()
      {
            myform.mylabel.value = "called Send";
            myform.mytextarea.value = myMailItem.Body;
      }

</script>
</head>
<body>
<form name="myform">
      <input type=text name="mylabel" value="Havent called Send"></label><BR>
      <textarea name="mytextarea"></textarea><br>
      <input type=button value="Send Email" name="Mysend" onclick="javascript:SendMail (myRecipient, mySubject, myBody);">
</form>
</body>
</html>
0
 
OzzModCommented:
Closed, 500 points refunded.
OzzMod
Community Support Moderator (Graveyard shift)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now