Mail getting stuck in the Outbox without being sent

G

g62msdnatll

I have an add-in that logs most events generated by Outlook 2003. I am
seeing that some mail messages that I compose are not getting sent through.
They get stuck in the Outbox, and clicking the Send/Receive button does not
cause those items to get sent.

My Inspector.Close event and ItemSend events do not seem to be hanging.
Neither do the Explorer.Activate/Deactivate events. How else could I debug
to see if my event handlers are causing this problem?

Are there any other sources of error that I might check?
 
P

Peter Huang [MSFT]

Hi

Will the mail hanged in the Outlook mailbox all the time or it will be sent
finally after a period of time?
Did the problem persists only in the programming mode or in the normal
outlook UI operation?
If you disable the addins, will the problem persists?

If you switch the folder back and forth will the mail be sent?

Based on my research, after installed windows xp sp2, there will be a delay
for the email to be sent.

Also if you still have any other concern, can you post the information
below?
1. What is your OS?(windows xp or 2000 ....)
2. What is your MailServer(Exchanger?, what is the version)

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
K

Ken Slovak - [MVP - Outlook]

One other thing to check is that you've released all object instances
related to the mail items. If an object reference is still live it can
prevent the object from being sent correctly.
 
G

g62msdnatll

Say I have multiple inspectors. Each inspector generates a new_inspector
event. For every new inspector, I update my reference to the
Outlook.Inspectors object, and also add the Inspector to a hashtable. On
Inspector.Close, how do I remove my reference to that Inspector? Do I need
to re-populate my hash of Inspector objects based on the Outlook.Inspectors
object?

I was keeping a hash of Inspector objects because I want to keep catching
activate/deactivate events, which I was missing after the first deactive,
apparently because the GC picked up my deactivated inspector and threw it
out, along with all my event handlers.
 
P

Peter Huang [MSFT]

Hi

Commonly we use the code similar as below to release COM Object.
//NOTE, if you still have a hash table reference to the comobject, you need
to set them to null all.

public void OnDisconnection(Extensibility.-ext_DisconnectMode
disconnectMode, ref System.Array custom)
{
if(srcItems !=null)
{
Marshal.ReleaseComObject(srcIt-ems);
srcItems = null;
}
if(desItems !=null)
{
Marshal.ReleaseComObject(desIt-ems);
desItems = null;
}
if(mi !=null)
{
Marshal.ReleaseComObject(mi);
mi = null;
}
if(Ips !=null)
{
Marshal.ReleaseComObject(Ips);
Ips = null;
}
if(olApp !=null)
{
Marshal.ReleaseComObject(olApp-);
olApp = null;
}


GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}


Also after we close a inspector, I think the object should be destroyed,
and a new inspector will invoke a new inspector object.
So I think it is better to track the Outlook.Inspectors object directly,
otherwise you have to update the hashtable frequently every time a
inspector is closed and a new inspector is reopened.

Have you tried my suggestion in my last post? I think it is necessary to
isolate the problem.
Also as Ken's suggestion, it may be caused by a unreleased com reference
that hold the mail item, so you may try to reduce the com object reference
as possible to locate the cause.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

g62msdnatll

Your suggestion of changing folders does not cause the mail item to get sent.
It is still stuck in the outbox. I printed statements at the beginning and
end of the ItemSend event, and both statements get printed. However, when
the item is getting stuck in the Outbox, I have noticed that the
Inspector.Deactivate event fires, but the Inspector.Close event does not fire.

As I mentioned earlier, I keep this hash because, for some reason, I noticed
that when the Inspector.Deactivate event fired, I would stop getting
Activate/Deactivate events on my Inspector (as if the GC was deleting my
object reference or something). When I added the hashtable for the Inspector
object, in addition to keeping a reference to the Inspectors, I continue to
get Activate/Deactivate events on an Inspector which has not been closed.

Do you understand my question? Please let me know if my assumption about
the Inspector hashtable is wrong.

SUMMARY:
My code keeps two object references:
1) Inspectors inspectors;
2) Hashtable inspHashtable;

New_Inspector(Inspector insp) {
inspHashtable.Add(insp.GetHashcode(), insp);
}

This way, when a new_inspector is created, but deactivated, I still get the
activate notification.

I was not getting an activate notification after a deactivate when I failed
to keep the hashtable of individual Inspector objects.
 
P

Peter Huang [MSFT]

Hi

I am sorry if I have any misunderstanding.
So far we need to confirm if this problem is caused by that the Inspector's
reference is held.
We need to isolate the problem via the steps below.
1. If we disable the addin the mail will no be locked in the outbox, so
that we can confirm the mail server works fine.
2. If we enable the adin but did not stored the inspector reference in the
hashtable and release it after using it, so that we can confirm the problem
is caused by the inspector reference is held in the hashtable.

If so, I think we may try to use the WeakReference to store in the
hashtable. The WeakReference can be GC when all the strong reference is
released.
WeakReference Class
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemweakreferenceclasstopic.asp

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
K

Ken Slovak - [MVP - Outlook]

What I do is subclass the Inspector and in the class module I handle events
for an Inspector (Close, Activate, etc.). Then I place all the classes into
a collection to keep the class (and therefore the Inspector) references
alive. When the Inspector closes I remove it from the collection.

I have an example of this on my Web site, but it's for VB 6. There's also an
example using C# at http://www.outlookcode.com/codedetail.aspx?id=797.

That's the best way to handle multiple Inspectors (and similar code is used
to handle multiple Explorers).
 
G

g62msdnatll

Hi Peter,

I believe I have isolated the problem on my machine. (but this is occurring
on other machines too, so I am not sure if it is the complete story)

On my machine:

If I compose a mail message with NO MESSAGE BODY, then the mail gets stuck
in the Outbox, and ALL SUBSEQUENTLY COMPOSED MESSAGES get stuck with it
(regardless of whether the subsequent messages have body text).

I access the message body on an ItemSend event by: passing mailitem.body to
a method that searches the characters for the string "//" to look for
possible URLs in the body.

CODE ACCESSING ITEM.BODY:

public static string ParseMessageBodyForURL(string body)
{
string s = null;
if (body == null)
{
return s;
}
int firstIndex = body.IndexOf("//");
int lastIndex = body.LastIndexOf("//");

while (firstIndex > -1)
{
//get url at index and pass it into parseurl to get info
string strURL = GetURLAtIndex(body, firstIndex);
firstIndex = body.IndexOf("//", firstIndex+1);
string strURLInfo = ParseURL(strURL);
// strCollection.Add(strURLInfo);
//add the string url info to the string that is being returned
s += strURLInfo + " ";
int length = System.Math.Min(95, strURL.Length);
//OutlookLogger.LogComment(Connect.fn, strURL.Substring(0,length));
s += strURL.Substring(0,length).ToLower().GetHashCode();
//OutlookLogger.LogComment(Connect.fn, strURL.Substring(0,
length).ToLower());
s += ";";
}

if (s == null)
{
return s;
}

else
{
char[] ch = new char[] {';'};
s = s.TrimEnd(ch);
return s;
}
}


Am I not allowed to access the message body on a send event?

Thank you for your help.
 
G

g62msdnatll

I also followed your steps:

1) I disabled the addin, mail is no longer locked in the Outbox (regardless
of whether the message body contains text)

2) Enabled the addin, but do not store the inspector reference in a
hashtable, mail continues to get stuck in the Outbox when there is no message
body, and after the first item is stuck in the Outbox, all subsequent items
are locked in the Outbox as well.

The ItemSend event is the only part of the code that accesses the item body.
However, the ItemSend event fires to completion. The event that does not
fire is Inspector.Close when a mailitem gets locked in the Outbox.
 
G

g62msdnatll

I have run across an instance of this error where there was a subject line.

1) The mail gets locked in the Outbox
2) Switch folder to Outbox folder
3) Open locked item
4) Click send to resend item
5) Send errors:

Task 'llpop - Sending' reported error (0x80040109) : 'The operation cannot
be performed because the message has been changed.'
 
P

Peter Huang [MSFT]

Hi

Based on my test, access to the mail.body will not block the mail in the
outbox. I test with the exchange server.

But from outlook 2002, all the attemtp to access to the mailitem and other
outlook item will invoke a secury dialog, this is a feature to prevent the
virus.
Administrator information about E-mail security features
http://support.microsoft.com/?id=290499

So I think you may try to isolate your code to see what is the problem.
e.g. first just hook the item send, and comment out others to see if that
works for you.

public void OnConnection(object application, Extensibility.ext_ConnectMode
connectMode, object addInInst, ref System.Array custom)
{
Debug.WriteLine("OnConnection");
olApp = application as Outlook.Application;
olApp.ItemSend+=new
Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(o
lApp_ItemSend);
}
public void OnDisconnection(Extensibility.ext_DisconnectMode
disconnectMode, ref System.Array custom)
{
if(mi !=null)
{
Marshal.ReleaseComObject(mi);
mi = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}
private Outlook.MailItem mi=null;

private void olApp_ItemSend(object Item, ref bool Cancel)
{
Debug.WriteLine("Item Send");
mi = Item as Outlook.MailItem;
string sBody = mi.Body;
Debug.WriteLine(sBody);
}

You may have a try.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

g62msdnatll

I really have no idea why there is this error. It's particularly bad on
another machine, but I can't debug it there because it is someone else's dev
machine.

When the item gets locked in that users Outbox, there was a pop-up dialog
box that displayed the following:

"The messaging interface has returned an unknown error. If the problem
persists, restart Outlook."

This error happens when:
1) user composes a message
2) User clicks "Send"
3) Item gets locked in Outbox
4) User opens message from Outbox and clicks "Send" again

I have followed your previous suggestion. The access of item.body is not
causing this error, as you predicted. Please help. I cannot deploy my
solution with this issue.

Again, as far as I can tell, there are absolutely not differences in
configuration between his machine and mine.
 
P

Peter Huang [MSFT]

Hi

It seems that there is something error with the outlook itself and the mail
account.
I assume the outlook addin did not work on the problem machine only, so it
may be related with the environment.
I think you may try to remove all the pst file from the outlook
temporatorily and delete and recreate the mail account with exchange, also
reinstall outlook if necessary.

If that still did not work, I think you may try to contact MSPSS directly.
http://support.microsoft.com

Thanks for your understanding!
If you still have any other concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
K

Ken Slovak - [MVP - Outlook]

We're beginning to see more of that sort of thing and it seems to be related
somehow to the use of .NET COM addins for Outlook. Are there any running on
the problem machine? If so disable them, either from the COM addins dialog
in Tools, Options or directly by setting LoadBehavior to 0 or 2 in both the
HKCU and HKLM registration hives. See if that fixes the problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top