Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / VS Tools for Office / June 2006

Tip: Looking for answers? Try searching our database.

Getting new and sent mail

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andy - 28 Jun 2006 16:22 GMT
Hi,

I'm trying to create an add-in which detects a newly sent mail or newly
received mail.

What I want to do is then check the email address (from for received
mail, to for sent mail) to see if its in a database, and then, if it
is, save the email to the database.

I'm using VS2005 Pro with VSTO; I've hooked up an event handler to
ItemSend and NewMail events, but I'm not sure how to figure out which
items are new or just sent.

Any suggestions?

Thanks
Andy
holzmann@meinlbank.com - 29 Jun 2006 09:34 GMT
Hi,

you can do this by handling the events for the folders..

<code>
..
// get MAPI namespace
Outlook.NameSpace mapiNamespace = this.GetNamespace("MAPI");

// get Outbox Folder .. sent mails will be added there before sending
Outlook.MAPIFolder _outboxMailFolder =
mapiNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);

// handle add item event
outboxMailItems.ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(outboxMailItems_ItemAdd);
...
//the add item event handler:
void outboxMailItems_ItemAdd(object Item)
       {
           Outlook.MailItem _newMail = Item as MOutlook.MailItem;
           if (_newMail != null)
           {
               try
               {
                   //do whatever you want with the mail...
               }
               finally
               {
                   // send the mail (seems this is not done
automatically when handling the itemadd event...
                   _newMail.Send();
               }
           }
       }
...

Philipp
_______________________
> Hi,
>
[quoted text clipped - 13 lines]
> Thanks
> Andy
Andy - 29 Jun 2006 13:23 GMT
Ahh, sounds like a better approach.

Thanks
Andy

> Hi,
>
[quoted text clipped - 34 lines]
>
> Philipp
Andy - 29 Jun 2006 20:27 GMT
Hey Philipp,

I wired up the events as you suggest, and i keep a reference to the
folder objects.  Everything works (it doesn't seem like I needed tell
the message to send, but i'm using the Sent mail box instead of the
outbox).  The only problem is when I try to remove the event handlers
on application shutdown, i get a null reference exception.

Any ideas how I can properly remove my event handlers?

Thanks
Andy

> Hi,
>
[quoted text clipped - 34 lines]
>
> Philipp
Andy - 30 Jun 2006 21:17 GMT
Got it figured out; had to keep a reference to the Items (not just the
mailbox) and from a blog on msdn, you also have to keep those
references static.

Everything works as expected now.

Andy

> Hey Philipp,
>
[quoted text clipped - 8 lines]
> Thanks
> Andy

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.