473,385 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

ItemSend doesn't work

I've got an outlook add-in. I'm running Outlook XP, .NET 1.1. My
Add-In is written in C#.

I'm trying to trap either the Application.ItemSend or the
MailItem.ItemSend event to put up a dialog and possibly let the user
cancel the send. I can get the events to fire, but setting the Cancel
flag doesn't work. I set Cancel to true, and the message is sent
anyway.

Here is the simple code. Again, my event handler does get called- I can
trap a breakpoint there. But, the cancel just doesn't work.
// this runs on startup, app is the application object
// handed to me by the extensibility interface
{
Outlook.Application myApp = (Outlook.Application)app;
myApp.ItemSend += new
Outlook.ApplicationEvents_10_ItemSendEventHandler( olApp_ItemSend);
}

private void olApp_ItemSend(object Item, ref bool Cancel)
{
Cancel = true;
}

Thanks!
Mike
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
2 2745


I found a good KB article on a problem similar to this in other outlook
apps. Its at http://support.microsoft.com/?id=830519. I think its the
same problem, although the KB article refers to Word and Excel rather
than Outlook.

I tried applying the fix in the KB article, and my custom sink helper
just never gets called. I have no idea why. Pretty sure I did it
right.

Anyone successful with this and Outlook?

Thanks,
Mike

Here is my ApplicationEventSinkHelper object:
using System;
using System.Runtime.InteropServices;
using Outlook; // The default name for a custom Word IA.
// If you use Office XP and you have the PIAs
// referenced in your project, you must change the previous line to
read:
// using Word = Microsoft.Office.Interop.Word;

//
// The following helper code attempts to work around a microsoft bug in
pre-Outlook2003.
// The problem is that the Cancel argument doesn't properly pass back in
the
// EventSend handler. See http://support.microsoft.com/?id=830519 for
details.
//
namespace OutlookApplicationEvents
{
/// <summary>
/// Hand-grown definition of the ItemEvents interface.
/// </summary>
[InterfaceType(ComInterfaceType.InterfaceIsIDispatc h),
GuidAttribute("0006304E-0000-0000-C000-000000000046")]
public interface DOutlookApplicationEvents
{
[DispId(0x0000f002)] void ItemSend(object Item, ref bool Cancel);
[DispId(0x0000f003)] void NewMail();
[DispId(0x0000f004)] void Reminder(object Item);
[DispId(0x0000f005)] void OptionsPagesAdd(Outlook.PropertyPages
Pages);
[DispId(0x0000f006)] void Startup();
[DispId(0x0000f007)] void Quit();
}

/// <summary>
/// Custom handler to help sync the events
/// </summary>
public class OutlookAppEventHelper : DOutlookApplicationEvents,
IDisposable
{
/// <summary>
/// ctor
/// </summary>
public OutlookAppEventHelper()
{
m_oConnectionPoint = null;
m_Cookie = 0;
}

public void ItemSend(object Item, ref bool Cancel)
{
System.Diagnostics.Debug.WriteLine("Got called");
}
public void NewMail()
{
System.Diagnostics.Debug.WriteLine("Got called");
}
public void Reminder(object Item)
{
System.Diagnostics.Debug.WriteLine("Got called");
}
public void OptionsPagesAdd(Outlook.PropertyPages Pages)
{
System.Diagnostics.Debug.WriteLine("Got called");
}
public void Startup()
{
System.Diagnostics.Debug.WriteLine("Got called");
}
public void Quit()
{
System.Diagnostics.Debug.WriteLine("Got called");
}


private UCOMIConnectionPoint m_oConnectionPoint;
private int m_Cookie;

/// <summary>
/// Setup a connection
/// </summary>
/// <param name="obj"></param>
public void SetupConnection(Outlook.Application obj)
{
if (m_Cookie != 0) return;

// GUID of the DIID_ItemEvents dispinterface.
Guid guid = new Guid("{0006304E-0000-0000-C000-000000000046}"); //
events

// QI for IConnectionPointContainer.
UCOMIConnectionPointContainer oConnPointContainer =
(UCOMIConnectionPointContainer)obj;

// Find the connection point and then advise.
oConnPointContainer.FindConnectionPoint(ref guid, out
m_oConnectionPoint);
m_oConnectionPoint.Advise(this, out m_Cookie);
}

/// <summary>
/// tear down a connection
/// </summary>
public void RemoveConnection()
{
if (m_Cookie != 0)
{
m_oConnectionPoint.Unadvise(m_Cookie);
m_oConnectionPoint = null;
m_Cookie = 0;
}
}

/// <summary>
/// Dispose
/// </summary>
public void Dispose()
{
RemoveConnection();
}

}
}
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #2
Mike,
The following site has a number of articles on using Outlook from .NET. Not
sure if one of them will address your problem.

http://www.microeye.com/resources/res_outlookvsnet.htm

Hope this helps
Jay

"Mike Belshe" <mi********@belshe.com> wrote in message
news:ec**************@TK2MSFTNGP11.phx.gbl...
I've got an outlook add-in. I'm running Outlook XP, .NET 1.1. My
Add-In is written in C#.

I'm trying to trap either the Application.ItemSend or the
MailItem.ItemSend event to put up a dialog and possibly let the user
cancel the send. I can get the events to fire, but setting the Cancel
flag doesn't work. I set Cancel to true, and the message is sent
anyway.

Here is the simple code. Again, my event handler does get called- I can
trap a breakpoint there. But, the cancel just doesn't work.
// this runs on startup, app is the application object
// handed to me by the extensibility interface
{
Outlook.Application myApp = (Outlook.Application)app;
myApp.ItemSend += new
Outlook.ApplicationEvents_10_ItemSendEventHandler( olApp_ItemSend);
}

private void olApp_ItemSend(object Item, ref bool Cancel)
{
Cancel = true;
}

Thanks!
Mike
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: AnnMarie | last post by:
My JavaScript Form Validation doesn't work at all in Netscape, but it works fine in IE. I made some of the suggested changes which enabled it to work in IE. I couldn't make all the changes...
39
by: Mark Johnson | last post by:
It doesn't seem possible. But would the following also seem a violation of the general notions behind css? You have a DIV, say asociated with class, 'topdiv'. Inside of that you have an anchor...
149
by: Christopher Benson-Manica | last post by:
(Followups set to comp.std.c. Apologies if the crosspost is unwelcome.) strchr() is to strrchr() as strstr() is to strrstr(), but strrstr() isn't part of the standard. Why not? --...
4
by: Andy Bates | last post by:
Hi - I am developing an application that needs to automate Microsoft Outlook and I need to capture the ItemSend event. The PC I'm developing with has Outlook 2003 on; the problem I have is I...
6
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType =...
4
by: bbp | last post by:
Hello, In an ASPX page I have a "Quit" button which make a simple redirect in code-behind. This button doesn't work no more since (I think) I moved from the framework 1.0 to 1.1 and it doesn't...
10
by: Sourcerer | last post by:
I wrote this very simple code in .NET VC++. I compiled it on my system, and tried to run it on my friend's computer (he doesn't have the compiler). We both have Windows XP Professional. I have .NET...
0
by: SteveHasel | last post by:
I'm working in Visual Studio 2005 trying to use Outlook to create an email and display it for the user to edit and then send. I need to be able to check that the item in the ItemSend event is my item...
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.