PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook Program Addins Exception thrown on MailItem.Send

Reply

Exception thrown on MailItem.Send

 
Thread Tools Rate Thread
Old 01-06-2007, 04:42 PM   #1
=?Utf-8?B?YnN0cnVt?=
Guest
 
Posts: n/a
Default Exception thrown on MailItem.Send


I am getting an exception thrown with our c# outlook addon installed on one
machine running Office 2003. The exception is thrown when I try to call Send
on a mail item that I have programatically created. The code looks like this:

Note: This code uses late binding.

// -- in the Item_Send event --
MSOutlook.MailItem mi; // assume initialized from the Item_Send argument

// create the new mail item that will be programatically sent
object otmp = mi.Application.CreateItem(MSOutlook.OlItemType.olMailItem);
MSOutlook.MailItem m = (MSOutlook.MailItem)MO.COMWrapper.Wrap(
otmp,
typeof(MSOutlook.MailItem));
m.BodyFormat = MSOutlook.OlBodyFormat.olFormatHTML;
m.To = mi.To;
m.Subject = "Some subject";
m.Body = "Test Body";
m.Save();
m.Send(); // throws exception on one client computer

The actual exception thrown is
"Exception has been thrown by the target of an invocation."

I have tried everything I can to duplicate the exception in our test
environment to no avail. Any ideas why something as simple as this would
throw an exception?

Thank you,

Ben Strum
ThinkTron Corporation
  Reply With Quote
Old 01-06-2007, 05:06 PM   #2
Sue Mosher [MVP-Outlook]
Guest
 
Posts: n/a
Default Re: Exception thrown on MailItem.Send

Try calling Recipients.ResolveAll and perform the send only if it returns True.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/article.aspx?id=54

"bstrum" <bstrum@discussions.microsoft.com> wrote in message news:078B8121-29D3-497C-A7FA-B635B2E6F6BB@microsoft.com...
>I am getting an exception thrown with our c# outlook addon installed on one
> machine running Office 2003. The exception is thrown when I try to call Send
> on a mail item that I have programatically created. The code looks like this:
>
> Note: This code uses late binding.
>
> // -- in the Item_Send event --
> MSOutlook.MailItem mi; // assume initialized from the Item_Send argument
>
> // create the new mail item that will be programatically sent
> object otmp = mi.Application.CreateItem(MSOutlook.OlItemType.olMailItem);
> MSOutlook.MailItem m = (MSOutlook.MailItem)MO.COMWrapper.Wrap(
> otmp,
> typeof(MSOutlook.MailItem));
> m.BodyFormat = MSOutlook.OlBodyFormat.olFormatHTML;
> m.To = mi.To;
> m.Subject = "Some subject";
> m.Body = "Test Body";
> m.Save();
> m.Send(); // throws exception on one client computer
>
> The actual exception thrown is
> "Exception has been thrown by the target of an invocation."
>
> I have tried everything I can to duplicate the exception in our test
> environment to no avail. Any ideas why something as simple as this would
> throw an exception?
>
> Thank you,
>
> Ben Strum
> ThinkTron Corporation

  Reply With Quote
Old 05-06-2007, 02:49 PM   #3
=?Utf-8?B?YnN0cnVt?=
Guest
 
Posts: n/a
Default Re: Exception thrown on MailItem.Send

The ResolveAll call is returning false on this one machine so the email does
not go out. Why would this happen? How can I get around this? I am sure
that the email address specified is valid and even if it is not, so what?

Lastly, is there a way to duplicate this in a test environment? Getting a
fix for this is really slow because it only happens on this one machine at a
client site.

Thank you,

-Ben

"Sue Mosher [MVP-Outlook]" wrote:

> Try calling Recipients.ResolveAll and perform the send only if it returns True.
>
> --
> Sue Mosher, Outlook MVP
> Author of Configuring Microsoft Outlook 2003
> http://www.turtleflock.com/olconfig/index.htm
> and Microsoft Outlook Programming - Jumpstart for
> Administrators, Power Users, and Developers
> http://www.outlookcode.com/article.aspx?id=54
>
> "bstrum" <bstrum@discussions.microsoft.com> wrote in message news:078B8121-29D3-497C-A7FA-B635B2E6F6BB@microsoft.com...
> >I am getting an exception thrown with our c# outlook addon installed on one
> > machine running Office 2003. The exception is thrown when I try to call Send
> > on a mail item that I have programatically created. The code looks like this:
> >
> > Note: This code uses late binding.
> >
> > // -- in the Item_Send event --
> > MSOutlook.MailItem mi; // assume initialized from the Item_Send argument
> >
> > // create the new mail item that will be programatically sent
> > object otmp = mi.Application.CreateItem(MSOutlook.OlItemType.olMailItem);
> > MSOutlook.MailItem m = (MSOutlook.MailItem)MO.COMWrapper.Wrap(
> > otmp,
> > typeof(MSOutlook.MailItem));
> > m.BodyFormat = MSOutlook.OlBodyFormat.olFormatHTML;
> > m.To = mi.To;
> > m.Subject = "Some subject";
> > m.Body = "Test Body";
> > m.Save();
> > m.Send(); // throws exception on one client computer
> >
> > The actual exception thrown is
> > "Exception has been thrown by the target of an invocation."
> >
> > I have tried everything I can to duplicate the exception in our test
> > environment to no avail. Any ideas why something as simple as this would
> > throw an exception?
> >
> > Thank you,
> >
> > Ben Strum
> > ThinkTron Corporation

>

  Reply With Quote
Old 05-06-2007, 03:54 PM   #4
Sue Mosher [MVP-Outlook]
Guest
 
Posts: n/a
Default Re: Exception thrown on MailItem.Send

This is not an appropriate way to copy recipients:

m.To = mi.To;

There is no guarantee that the display names, which is what To shows, will resolve to valid addresses. Instead, you need to iterate the mi.Recipients collection and use m.Recipients.Add to create a new Recipient based on the information from the original item.

To test, use one or more recipients whose display names are radically different from their actual email addresses.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/article.aspx?id=54

"bstrum" <bstrum@discussions.microsoft.com> wrote in message news:5134F1F0-AF4D-48F9-AF2C-4929C408A518@microsoft.com...
> The ResolveAll call is returning false on this one machine so the email does
> not go out. Why would this happen? How can I get around this? I am sure
> that the email address specified is valid and even if it is not, so what?


> Lastly, is there a way to duplicate this in a test environment? Getting a
> fix for this is really slow because it only happens on this one machine at a
> client site.
>
> Thank you,
>
> -Ben
>
> "Sue Mosher [MVP-Outlook]" wrote:
>
>> Try calling Recipients.ResolveAll and perform the send only if it returns True.


>>
>> "bstrum" <bstrum@discussions.microsoft.com> wrote in message news:078B8121-29D3-497C-A7FA-B635B2E6F6BB@microsoft.com...
>> >I am getting an exception thrown with our c# outlook addon installed on one
>> > machine running Office 2003. The exception is thrown when I try to call Send
>> > on a mail item that I have programatically created. The code looks like this:
>> >
>> > Note: This code uses late binding.
>> >
>> > // -- in the Item_Send event --
>> > MSOutlook.MailItem mi; // assume initialized from the Item_Send argument
>> >
>> > // create the new mail item that will be programatically sent
>> > object otmp = mi.Application.CreateItem(MSOutlook.OlItemType.olMailItem);
>> > MSOutlook.MailItem m = (MSOutlook.MailItem)MO.COMWrapper.Wrap(
>> > otmp,
>> > typeof(MSOutlook.MailItem));
>> > m.BodyFormat = MSOutlook.OlBodyFormat.olFormatHTML;
>> > m.To = mi.To;
>> > m.Subject = "Some subject";
>> > m.Body = "Test Body";
>> > m.Save();
>> > m.Send(); // throws exception on one client computer
>> >
>> > The actual exception thrown is
>> > "Exception has been thrown by the target of an invocation."
>> >
>> > I have tried everything I can to duplicate the exception in our test
>> > environment to no avail. Any ideas why something as simple as this would
>> > throw an exception?
>> >
>> > Thank you,
>> >
>> > Ben Strum
>> > ThinkTron Corporation

>>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off