PC Review


Reply
Thread Tools Rate Thread

Bypassing Outlook's Outbox (or creating a custom outbox)

 
 
Ekin
Guest
Posts: n/a
 
      18th Jan 2008
Here's my problem: When the user creates a new email (or forwards, replies,
etc), I want the email to go to my MAPIFolder instead of Outbox. When I try
to do this at Application_ItemSend by Item.Move(), I'm getting the mail
deleted or moved error for obvious reasons.

Note that I don't want Outlook to send the emails, I want to handle that
myself. So SaveSentMessageFolder doesn't help. If only there was a
OutboxFolder member of the MailItem class!

Any ideas how I could achieve this?

Ekin
 
Reply With Quote
 
 
 
 
Sue Mosher [MVP-Outlook]
Guest
Posts: n/a
 
      18th Jan 2008
Please clarify what you're trying to accomplish. The Outbox is only a temporary holding area for messages that have not been delivered to the downstream server.

Also, why are you creating messages in the first place if you don't want Outlook to send them?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Ekin" <(E-Mail Removed)> wrote in message news:B794ABDD-9F0B-404F-A395-(E-Mail Removed)...
> Here's my problem: When the user creates a new email (or forwards, replies,
> etc), I want the email to go to my MAPIFolder instead of Outbox. When I try
> to do this at Application_ItemSend by Item.Move(), I'm getting the mail
> deleted or moved error for obvious reasons.
>
> Note that I don't want Outlook to send the emails, I want to handle that
> myself. So SaveSentMessageFolder doesn't help. If only there was a
> OutboxFolder member of the MailItem class!
>
> Any ideas how I could achieve this?
>
> Ekin

 
Reply With Quote
 
Ekin
Guest
Posts: n/a
 
      18th Jan 2008
I'm trying to move the mail item to a temporary folder (myOutbox), process it
(which may take up to 10-20 seconds), and pass it back to Outlook's default
Outbox.

See my ItemSend below.

Private Sub ThisApplication_ItemSend(ByVal Item As Object, ByRef Cancel
As Boolean) Handles Me.ItemSend
If (Item.Parent.EntryID = _outlookOutbox.EntryID) OrElse _
(Item.Parent.EntryID = _myOutbox.EntryID) Then
Cancel = False
Else
Item.Move(_myOutbox)
Cancel = True
End If
End Sub

I also tried to do the same with Inspectors but got the same "The item has
been moved or deleted" error.

Ekin

"Sue Mosher [MVP-Outlook]" wrote:

> Please clarify what you're trying to accomplish. The Outbox is only a temporary holding area for messages that have not been delivered to the downstream server.
>
> Also, why are you creating messages in the first place if you don't want Outlook to send them?
> --
> Sue Mosher, Outlook MVP
> Author of Microsoft Outlook 2007 Programming:
> Jumpstart for Power Users and Administrators
> http://www.outlookcode.com/article.aspx?id=54
>
>
> "Ekin" <(E-Mail Removed)> wrote in message news:B794ABDD-9F0B-404F-A395-(E-Mail Removed)...
> > Here's my problem: When the user creates a new email (or forwards, replies,
> > etc), I want the email to go to my MAPIFolder instead of Outbox. When I try
> > to do this at Application_ItemSend by Item.Move(), I'm getting the mail
> > deleted or moved error for obvious reasons.
> >
> > Note that I don't want Outlook to send the emails, I want to handle that
> > myself. So SaveSentMessageFolder doesn't help. If only there was a
> > OutboxFolder member of the MailItem class!
> >
> > Any ideas how I could achieve this?
> >
> > Ekin

>

 
Reply With Quote
 
Ekin
Guest
Posts: n/a
 
      18th Jan 2008
Oh, the Item is moved correctly and the rest of my code works as it should.
So it's just a matter of avoiding the nasty Outlook error...

Ekin

"Ekin" wrote:

> I'm trying to move the mail item to a temporary folder (myOutbox), process it
> (which may take up to 10-20 seconds), and pass it back to Outlook's default
> Outbox.
>
> See my ItemSend below.
>
> Private Sub ThisApplication_ItemSend(ByVal Item As Object, ByRef Cancel
> As Boolean) Handles Me.ItemSend
> If (Item.Parent.EntryID = _outlookOutbox.EntryID) OrElse _
> (Item.Parent.EntryID = _myOutbox.EntryID) Then
> Cancel = False
> Else
> Item.Move(_myOutbox)
> Cancel = True
> End If
> End Sub
>
> I also tried to do the same with Inspectors but got the same "The item has
> been moved or deleted" error.
>
> Ekin
>
> "Sue Mosher [MVP-Outlook]" wrote:
>
> > Please clarify what you're trying to accomplish. The Outbox is only a temporary holding area for messages that have not been delivered to the downstream server.
> >
> > Also, why are you creating messages in the first place if you don't want Outlook to send them?
> > --
> > Sue Mosher, Outlook MVP
> > Author of Microsoft Outlook 2007 Programming:
> > Jumpstart for Power Users and Administrators
> > http://www.outlookcode.com/article.aspx?id=54
> >
> >
> > "Ekin" <(E-Mail Removed)> wrote in message news:B794ABDD-9F0B-404F-A395-(E-Mail Removed)...
> > > Here's my problem: When the user creates a new email (or forwards, replies,
> > > etc), I want the email to go to my MAPIFolder instead of Outbox. When I try
> > > to do this at Application_ItemSend by Item.Move(), I'm getting the mail
> > > deleted or moved error for obvious reasons.
> > >
> > > Note that I don't want Outlook to send the emails, I want to handle that
> > > myself. So SaveSentMessageFolder doesn't help. If only there was a
> > > OutboxFolder member of the MailItem class!
> > >
> > > Any ideas how I could achieve this?
> > >
> > > Ekin

> >

 
Reply With Quote
 
Sue Mosher [MVP-Outlook]
Guest
Posts: n/a
 
      18th Jan 2008
You can always use On Error Resume Next to suppress most error messages.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Ekin" <(E-Mail Removed)> wrote in message news:0D250B84-7B9E-4C45-A71D-(E-Mail Removed)...
> Oh, the Item is moved correctly and the rest of my code works as it should.
> So it's just a matter of avoiding the nasty Outlook error...
>
> Ekin
>
> "Ekin" wrote:
>
>> I'm trying to move the mail item to a temporary folder (myOutbox), process it
>> (which may take up to 10-20 seconds), and pass it back to Outlook's default
>> Outbox.
>>
>> See my ItemSend below.
>>
>> Private Sub ThisApplication_ItemSend(ByVal Item As Object, ByRef Cancel
>> As Boolean) Handles Me.ItemSend
>> If (Item.Parent.EntryID = _outlookOutbox.EntryID) OrElse _
>> (Item.Parent.EntryID = _myOutbox.EntryID) Then
>> Cancel = False
>> Else
>> Item.Move(_myOutbox)
>> Cancel = True
>> End If
>> End Sub
>>
>> I also tried to do the same with Inspectors but got the same "The item has
>> been moved or deleted" error.
>>
>> Ekin
>>
>> "Sue Mosher [MVP-Outlook]" wrote:
>>
>> > Please clarify what you're trying to accomplish. The Outbox is only a temporary holding area for messages that have not been delivered to the downstream server.
>> >
>> > Also, why are you creating messages in the first place if you don't want Outlook to send them?


>> >
>> > "Ekin" <(E-Mail Removed)> wrote in message news:B794ABDD-9F0B-404F-A395-(E-Mail Removed)...
>> > > Here's my problem: When the user creates a new email (or forwards, replies,
>> > > etc), I want the email to go to my MAPIFolder instead of Outbox. When I try
>> > > to do this at Application_ItemSend by Item.Move(), I'm getting the mail
>> > > deleted or moved error for obvious reasons.
>> > >
>> > > Note that I don't want Outlook to send the emails, I want to handle that
>> > > myself. So SaveSentMessageFolder doesn't help. If only there was a
>> > > OutboxFolder member of the MailItem class!
>> > >
>> > > Any ideas how I could achieve this?
>> > >
>> > > Ekin
>> >

 
Reply With Quote
 
Ekin
Guest
Posts: n/a
 
      18th Jan 2008
Thank you, Sue, but that didn't work.

When I debug in VS and follow the ThisApplication_ItemSend through line by
line, I can get to End Sub without any errors; when I hit F10 on End Sub, the
annoying "The item has been moved or deleted" message is thrown by Outlook
--VS Interop isn't even aware of it! So as far as VB is concerned, there is
no error.

Problem remains...

Ekin

"Sue Mosher [MVP-Outlook]" wrote:

> You can always use On Error Resume Next to suppress most error messages.
>
> --
> Sue Mosher, Outlook MVP
> Author of Microsoft Outlook 2007 Programming:
> Jumpstart for Power Users and Administrators
> http://www.outlookcode.com/article.aspx?id=54
>
>
> "Ekin" <(E-Mail Removed)> wrote in message news:0D250B84-7B9E-4C45-A71D-(E-Mail Removed)...
> > Oh, the Item is moved correctly and the rest of my code works as it should.
> > So it's just a matter of avoiding the nasty Outlook error...
> >
> > Ekin
> >
> > "Ekin" wrote:
> >
> >> I'm trying to move the mail item to a temporary folder (myOutbox), process it
> >> (which may take up to 10-20 seconds), and pass it back to Outlook's default
> >> Outbox.
> >>
> >> See my ItemSend below.
> >>
> >> Private Sub ThisApplication_ItemSend(ByVal Item As Object, ByRef Cancel
> >> As Boolean) Handles Me.ItemSend
> >> If (Item.Parent.EntryID = _outlookOutbox.EntryID) OrElse _
> >> (Item.Parent.EntryID = _myOutbox.EntryID) Then
> >> Cancel = False
> >> Else
> >> Item.Move(_myOutbox)
> >> Cancel = True
> >> End If
> >> End Sub
> >>
> >> I also tried to do the same with Inspectors but got the same "The item has
> >> been moved or deleted" error.
> >>
> >> Ekin
> >>
> >> "Sue Mosher [MVP-Outlook]" wrote:
> >>
> >> > Please clarify what you're trying to accomplish. The Outbox is only a temporary holding area for messages that have not been delivered to the downstream server.
> >> >
> >> > Also, why are you creating messages in the first place if you don't want Outlook to send them?

>
> >> >
> >> > "Ekin" <(E-Mail Removed)> wrote in message news:B794ABDD-9F0B-404F-A395-(E-Mail Removed)...
> >> > > Here's my problem: When the user creates a new email (or forwards, replies,
> >> > > etc), I want the email to go to my MAPIFolder instead of Outbox. When I try
> >> > > to do this at Application_ItemSend by Item.Move(), I'm getting the mail
> >> > > deleted or moved error for obvious reasons.
> >> > >
> >> > > Note that I don't want Outlook to send the emails, I want to handle that
> >> > > myself. So SaveSentMessageFolder doesn't help. If only there was a
> >> > > OutboxFolder member of the MailItem class!
> >> > >
> >> > > Any ideas how I could achieve this?
> >> > >
> >> > > Ekin
> >> >

>

 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      18th Jan 2008
It might work better if you do that in item.Send rather than in the
application wide event. Also, generally it's better to cancel the send, set
a flag and check the flag later using a timer or something to first get out
of the send event before you try to move the item. At least that's what I've
found doing similar things.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Ekin" <(E-Mail Removed)> wrote in message
news957626D-A6CC-4C6E-B845-(E-Mail Removed)...
> Thank you, Sue, but that didn't work.
>
> When I debug in VS and follow the ThisApplication_ItemSend through line by
> line, I can get to End Sub without any errors; when I hit F10 on End Sub,
> the
> annoying "The item has been moved or deleted" message is thrown by Outlook
> --VS Interop isn't even aware of it! So as far as VB is concerned, there
> is
> no error.
>
> Problem remains...
>
> Ekin


 
Reply With Quote
 
Ekin
Guest
Posts: n/a
 
      19th Jan 2008
Thank you Ken. I tired with Item.Send (via inspectors) and had no luck.
Managing a dictionary of EntryIDs and going through them inside a timer tick
doesn't sound too reliable, mainly because the user may do something else
with the email if it remains open.

In my ItemSend, I added the following lines:
CloneMailItem(Item).Move(_myOutbox)
DeleteMailItem(Item)
Cancel = True

DeleteMailItem does item.Delete(), Marshal.ReleaseComObject(item) and
item=Nothing.

CloneMailItem creates a NEW MailItem object and gets a member by member copy
of the input item. newItem.To = item.To, newItem.CC = item.CC, .... (Binary
serialization doesn't work as MailItem isn't serializable.)

Now, the new item doesn't have any pointers back to Item in ItemSend and
everything works fine without "Send operation failed because the item was
deleted" and "The item has been moved or deleted" errors / notifications.

So if I could ditch the CloneMailItem function and use newitem =
item.Move(_myOutbox) and somehow dispose the pointer from newitem to Item, my
problem would be solved. Marshal.ReleaseComObject(newitem) and newitem =
Nothing don't do the trick.

Any ideas?

Ekin

"Ken Slovak - [MVP - Outlook]" wrote:

> It might work better if you do that in item.Send rather than in the
> application wide event. Also, generally it's better to cancel the send, set
> a flag and check the flag later using a timer or something to first get out
> of the send event before you try to move the item. At least that's what I've
> found doing similar things.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007
> Reminder Manager, Extended Reminders, Attachment Options
> http://www.slovaktech.com/products.htm
>
>
> "Ekin" <(E-Mail Removed)> wrote in message
> news957626D-A6CC-4C6E-B845-(E-Mail Removed)...
> > Thank you, Sue, but that didn't work.
> >
> > When I debug in VS and follow the ThisApplication_ItemSend through line by
> > line, I can get to End Sub without any errors; when I hit F10 on End Sub,
> > the
> > annoying "The item has been moved or deleted" message is thrown by Outlook
> > --VS Interop isn't even aware of it! So as far as VB is concerned, there
> > is
> > no error.
> >
> > Problem remains...
> >
> > Ekin

>
>

 
Reply With Quote
 
Dmitry Streblechenko
Guest
Posts: n/a
 
      19th Jan 2008
As long your timer interval is not 2 minutes, the user won't have a chance
to do anything.
Thee important part is that your cannot delete or move the message while
Outlook is still processing the event callback. If the timer interval is 0,
it will fire immediately after Outlook runs the Windows message loop, but by
that time Outlook will be out of the event callback.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Ekin" <(E-Mail Removed)> wrote in message
news:9B894B9A-96C6-428A-AC67-(E-Mail Removed)...
> Thank you Ken. I tired with Item.Send (via inspectors) and had no luck.
> Managing a dictionary of EntryIDs and going through them inside a timer
> tick
> doesn't sound too reliable, mainly because the user may do something else
> with the email if it remains open.
>
> In my ItemSend, I added the following lines:
> CloneMailItem(Item).Move(_myOutbox)
> DeleteMailItem(Item)
> Cancel = True
>
> DeleteMailItem does item.Delete(), Marshal.ReleaseComObject(item) and
> item=Nothing.
>
> CloneMailItem creates a NEW MailItem object and gets a member by member
> copy
> of the input item. newItem.To = item.To, newItem.CC = item.CC, ....
> (Binary
> serialization doesn't work as MailItem isn't serializable.)
>
> Now, the new item doesn't have any pointers back to Item in ItemSend and
> everything works fine without "Send operation failed because the item was
> deleted" and "The item has been moved or deleted" errors / notifications.
>
> So if I could ditch the CloneMailItem function and use newitem =
> item.Move(_myOutbox) and somehow dispose the pointer from newitem to Item,
> my
> problem would be solved. Marshal.ReleaseComObject(newitem) and newitem =
> Nothing don't do the trick.
>
> Any ideas?
>
> Ekin
>
> "Ken Slovak - [MVP - Outlook]" wrote:
>
>> It might work better if you do that in item.Send rather than in the
>> application wide event. Also, generally it's better to cancel the send,
>> set
>> a flag and check the flag later using a timer or something to first get
>> out
>> of the send event before you try to move the item. At least that's what
>> I've
>> found doing similar things.
>>
>> --
>> Ken Slovak
>> [MVP - Outlook]
>> http://www.slovaktech.com
>> Author: Professional Programming Outlook 2007
>> Reminder Manager, Extended Reminders, Attachment Options
>> http://www.slovaktech.com/products.htm
>>
>>
>> "Ekin" <(E-Mail Removed)> wrote in message
>> news957626D-A6CC-4C6E-B845-(E-Mail Removed)...
>> > Thank you, Sue, but that didn't work.
>> >
>> > When I debug in VS and follow the ThisApplication_ItemSend through line
>> > by
>> > line, I can get to End Sub without any errors; when I hit F10 on End
>> > Sub,
>> > the
>> > annoying "The item has been moved or deleted" message is thrown by
>> > Outlook
>> > --VS Interop isn't even aware of it! So as far as VB is concerned,
>> > there
>> > is
>> > no error.
>> >
>> > Problem remains...
>> >
>> > Ekin

>>
>>



 
Reply With Quote
 
Ekin
Guest
Posts: n/a
 
      20th Jan 2008
Right, it works with the following structure, even though Outlook's response
doesn't feel "natural" with a 100ms timer:

ThisApplication_Startup
_ToBeProcessed = New Collection
_moveTimer = New Timer
_moveTimer.Interval = 100
_moveTimer.Start()

ThisApplication_ItemSend
_ToBeProcessed.Add(Item)
Cancel = True

Private Sub _moveTimer_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles _moveTimer.Tick
If _ToBeProcessed.Count > 0 Then
For x As Integer = 1 To _ToBeProcessed.Count
CType(_ToBeProcessed(x), MailItem).Move(_myOutbox)
_ToBeProcessed.Remove(x)
Next
End If
End Sub

Do all the MVPs here think this really is the way to do it?

With the timer_tick running so frequently,
- What's the strain on system resources?
- Are there any concurrency issues? (is the function executed if it's
already being processed since the last timer tick?)

Ekin

Ps: Dmitry, re your "you cannot delete or move the message while Outlook is
still processing the event callback" comment. item.Delete():
Marshal.ReleaseComObject(item): item = Nothing does exactly that in ItemSend,
unless you meant something else...

"Dmitry Streblechenko" wrote:

> As long your timer interval is not 2 minutes, the user won't have a chance
> to do anything.
> Thee important part is that your cannot delete or move the message while
> Outlook is still processing the event callback. If the timer interval is 0,
> it will fire immediately after Outlook runs the Windows message loop, but by
> that time Outlook will be out of the event callback.
>
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy - Outlook, CDO
> and MAPI Developer Tool
>
> "Ekin" <(E-Mail Removed)> wrote in message
> news:9B894B9A-96C6-428A-AC67-(E-Mail Removed)...
> > Thank you Ken. I tired with Item.Send (via inspectors) and had no luck.
> > Managing a dictionary of EntryIDs and going through them inside a timer
> > tick
> > doesn't sound too reliable, mainly because the user may do something else
> > with the email if it remains open.
> >
> > In my ItemSend, I added the following lines:
> > CloneMailItem(Item).Move(_myOutbox)
> > DeleteMailItem(Item)
> > Cancel = True
> >
> > DeleteMailItem does item.Delete(), Marshal.ReleaseComObject(item) and
> > item=Nothing.
> >
> > CloneMailItem creates a NEW MailItem object and gets a member by member
> > copy
> > of the input item. newItem.To = item.To, newItem.CC = item.CC, ....
> > (Binary
> > serialization doesn't work as MailItem isn't serializable.)
> >
> > Now, the new item doesn't have any pointers back to Item in ItemSend and
> > everything works fine without "Send operation failed because the item was
> > deleted" and "The item has been moved or deleted" errors / notifications.
> >
> > So if I could ditch the CloneMailItem function and use newitem =
> > item.Move(_myOutbox) and somehow dispose the pointer from newitem to Item,
> > my
> > problem would be solved. Marshal.ReleaseComObject(newitem) and newitem =
> > Nothing don't do the trick.
> >
> > Any ideas?
> >
> > Ekin
> >
> > "Ken Slovak - [MVP - Outlook]" wrote:
> >
> >> It might work better if you do that in item.Send rather than in the
> >> application wide event. Also, generally it's better to cancel the send,
> >> set
> >> a flag and check the flag later using a timer or something to first get
> >> out
> >> of the send event before you try to move the item. At least that's what
> >> I've
> >> found doing similar things.
> >>
> >> --
> >> Ken Slovak
> >> [MVP - Outlook]
> >> http://www.slovaktech.com
> >> Author: Professional Programming Outlook 2007
> >> Reminder Manager, Extended Reminders, Attachment Options
> >> http://www.slovaktech.com/products.htm
> >>
> >>
> >> "Ekin" <(E-Mail Removed)> wrote in message
> >> news957626D-A6CC-4C6E-B845-(E-Mail Removed)...
> >> > Thank you, Sue, but that didn't work.
> >> >
> >> > When I debug in VS and follow the ThisApplication_ItemSend through line
> >> > by
> >> > line, I can get to End Sub without any errors; when I hit F10 on End
> >> > Sub,
> >> > the
> >> > annoying "The item has been moved or deleted" message is thrown by
> >> > Outlook
> >> > --VS Interop isn't even aware of it! So as far as VB is concerned,
> >> > there
> >> > is
> >> > no error.
> >> >
> >> > Problem remains...
> >> >
> >> > Ekin
> >>
> >>

>
>
>

 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unsent messages in outbox, and unable to delete message in outbox =?Utf-8?B?R2luYS1PaGlv?= Windows Vista Mail 1 2nd Oct 2007 04:59 PM
Messages stuck outbox-WMUtil is not clearing outbox. Error message =?Utf-8?B?TWFtYXNpdGE=?= Windows Vista Mail 18 11th Jul 2007 06:52 PM
Outlook Outbox shows wrong number of messages in outbox. =?Utf-8?B?TGVu?= Microsoft Outlook Discussion 0 22nd Apr 2007 09:10 PM
Folder list shows items in outbox, but nothing is in outbox =?Utf-8?B?c3VzaWU=?= Microsoft Outlook Discussion 0 14th Sep 2006 01:56 PM
Outlook 2000 Outbox won't send once the Outbox folder has been opened Susan Microsoft Outlook 4 29th Aug 2004 06:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:44 PM.