WUGNET, the Windows User Group Network
Your Complete Resource Center for "The Best" in Shareware, Computing Tips and Support, Windows Industry News... and much more!
Home Forums Shareware Windows Tips Hot Offers FREE Newsletters Arcade Contact Us About Partners
Search WUGNET: RSS Feeds RSS Feeds Advertise with WUGNET    |    Shareware eBooks
HomeHome FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

trap outbound mail to update subject

 
   Home -> Office -> Programming VBA RSS
Next:  How do i stop tasks automatically saving?  
Author Message
andy tomic

External


Since: Jul 06, 2009
Posts: 1



(Msg. 1) Posted: Mon Jul 06, 2009 9:29 pm
Post subject: trap outbound mail to update subject
Archived from groups: microsoft>public>outlook>program_vba (more info?)

Hi all

Getting a little stuck on my outbound rules / vba code. I currently
run an excellent addin called TAGLOCITY which tags emails with
categories. What I am trying to do PREFIX the mail subject based on
the category. NOTE: The taglocity addin triggers a category request
AFTER the item.send action.

for example;
I have a category "100 Love St" (this is my project name)
I have a color for all PROJECTS -- construction project are DARKGREEN
When I send the mail I want the addin to check the subject for a ":"
Then if there is no ":", prefix with "Job:" and the category.

I have the code for this and it works fine if i manually trigger the
vba code. I have a rule to hold the email in outbox for 1minute to
give the program time to modify and for me to go in and cancel the send
Wink . My question is how can I trigger the code to work AFTER the
item.send command and there after the TAGLOCITY addin has had a chance
to add in the category.

code below:
Sub PrefixMailItemInOutbox()
Dim oNS As Outlook.NameSpace
Dim oFld As Outlook.Folder
Dim oItems As Outlook.Items
Dim oItem As Object
Dim Item As Outlook.MailItem

On Error GoTo OL_Error

Set oNS = Application.GetNamespace("MAPI")
Set oFld = oNS.GetDefaultFolder(olFolderOutbox)

Set oItems = oFld.Items
'Set objItem = GetCurrentItem()
StoreID = oFld.StoreID

For Each oItem In oItems
If InStr(1, oItem.Subject, ":", vbTextCompare) = 0 Then

If Len(oItem.Categories) > 0 Then
Set objItem = oNS.GetItemFromID(oItem.EntryID, StoreID)

For Each objCategory In oNS.Categories
If InStr(1, objItem.Categories, objCategory.Name, vbTextCompare)
> 0 Then
Select Case objCategory.Color
Case OlCategoryColor.olCategoryColorDarkRed
objItem.Subject = "Roofing:" & objCategory.Name & " - "
& objItem.Subject
objItem.Save
Case OlCategoryColor.olCategoryColorBlack
objItem.Subject = "Carpentry:" & objCategory.Name & " -
" & objItem.Subject
objItem.Save
Case OlCategoryColor.olCategoryColorDarkGreen
objItem.Subject = "Job:" & objCategory.Name & " - " &
objItem.Subject
objItem.Save
End Select
End If
Next
End If
objItem.Send
'Set objItem = Nothing
End If

Next

Exit Sub
OL_Error:
MsgBox Err.Description
Err.Clear
End Sub

Thanks in advance

Andy




--
andy tomic
Back to top
Login to vote
Alan Moseley

External


Since: Oct 20, 2008
Posts: 51



(Msg. 2) Posted: Tue Jul 07, 2009 2:40 am
Post subject: RE: trap outbound mail to update subject [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hook into the Application.ItemSend event in the ThisOutlookSession code
window. It gets passed the email that is being sent so that you can
manipulate it:-

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim myItem As MailItem
If TypeName(Item) = "olMailItem" Then
Set myItem = Item
'Do something here such as call your routine passing the myItem object
End If
End Sub

I guess that your addin is already hooking into this event, so I am not sure
whether this would run before or after the addin, perhaps someone else can
advise.

--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.


"andy tomic" wrote:

>
> Hi all
>
> Getting a little stuck on my outbound rules / vba code. I currently
> run an excellent addin called TAGLOCITY which tags emails with
> categories. What I am trying to do PREFIX the mail subject based on
> the category. NOTE: The taglocity addin triggers a category request
> AFTER the item.send action.
>
> for example;
> I have a category "100 Love St" (this is my project name)
> I have a color for all PROJECTS -- construction project are DARKGREEN
> When I send the mail I want the addin to check the subject for a ":"
> Then if there is no ":", prefix with "Job:" and the category.
>
> I have the code for this and it works fine if i manually trigger the
> vba code. I have a rule to hold the email in outbox for 1minute to
> give the program time to modify and for me to go in and cancel the send
> Wink . My question is how can I trigger the code to work AFTER the
> item.send command and there after the TAGLOCITY addin has had a chance
> to add in the category.
>
> code below:
> Sub PrefixMailItemInOutbox()
> Dim oNS As Outlook.NameSpace
> Dim oFld As Outlook.Folder
> Dim oItems As Outlook.Items
> Dim oItem As Object
> Dim Item As Outlook.MailItem
>
> On Error GoTo OL_Error
>
> Set oNS = Application.GetNamespace("MAPI")
> Set oFld = oNS.GetDefaultFolder(olFolderOutbox)
>
> Set oItems = oFld.Items
> 'Set objItem = GetCurrentItem()
> StoreID = oFld.StoreID
>
> For Each oItem In oItems
> If InStr(1, oItem.Subject, ":", vbTextCompare) = 0 Then
>
> If Len(oItem.Categories) > 0 Then
> Set objItem = oNS.GetItemFromID(oItem.EntryID, StoreID)
>
> For Each objCategory In oNS.Categories
> If InStr(1, objItem.Categories, objCategory.Name, vbTextCompare)
> > 0 Then
> Select Case objCategory.Color
> Case OlCategoryColor.olCategoryColorDarkRed
> objItem.Subject = "Roofing:" & objCategory.Name & " - "
> & objItem.Subject
> objItem.Save
> Case OlCategoryColor.olCategoryColorBlack
> objItem.Subject = "Carpentry:" & objCategory.Name & " -
> " & objItem.Subject
> objItem.Save
> Case OlCategoryColor.olCategoryColorDarkGreen
> objItem.Subject = "Job:" & objCategory.Name & " - " &
> objItem.Subject
> objItem.Save
> End Select
> End If
> Next
> End If
> objItem.Send
> 'Set objItem = Nothing
> End If
>
> Next
>
> Exit Sub
> OL_Error:
> MsgBox Err.Description
> Err.Clear
> End Sub
>
> Thanks in advance
>
> Andy
>
>
>
>
> --
> andy tomic
>
Back to top
Login to vote
Ken Slovak - [MVP - Outlo

External


Since: Oct 17, 2003
Posts: 2977



(Msg. 3) Posted: Tue Jul 07, 2009 9:12 am
Post subject: Re: trap outbound mail to update subject [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

It's impossible to determine what addin will run things in what order. It
depends on the load order of the addins (Outlook VBA is just another COM
addin) and which ones register for which events in which order.

If that addin is actually hooking to Application.ItemSend() then it might be
after or before a VBA hook. If the VBA code must be after the addin massages
the data then using an earlier event such as item.Send() wouldn't help, but
many addins do use that event rather than Application.ItemSend() since that
fires after the email transport is engaged and so is too late for some item
manipulations.

--
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


"Alan Moseley" <AlanMoseley.RemoveThis@discussions.microsoft.com> wrote in message
news:13D86EBE-ED55-4003-BAA7-2C0C6FB7492A@microsoft.com...
> Hook into the Application.ItemSend event in the ThisOutlookSession code
> window. It gets passed the email that is being sent so that you can
> manipulate it:-
>
> Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
> Dim myItem As MailItem
> If TypeName(Item) = "olMailItem" Then
> Set myItem = Item
> 'Do something here such as call your routine passing the myItem
> object
> End If
> End Sub
>
> I guess that your addin is already hooking into this event, so I am not
> sure
> whether this would run before or after the addin, perhaps someone else can
> advise.
>
> --
> Alan Moseley IT Consultancy
> http://www.amitc.co.uk
>
> If I have solved your problem, please click Yes below. Thanks.
>
Back to top
Login to vote
andy tomic

External


Since: Jul 09, 2009
Posts: 1



(Msg. 4) Posted: Thu Jul 09, 2009 6:05 pm
Post subject: Re: trap outbound mail to update subject [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thank you Alan and Ken.

The addin is definitely triggered after the Application.ItemSend event.


What I was thinking as a work around is to delay the message in the
outbox for 1 min using a rule. Then manipulate the message with the
code. My only shortfall is that I have not the knowledge to create a
CUSTOM ACTION in the rules section.

Is there a simple way to call the procedure once the email gets into
the outbox ??

Thanking you in advance

Andy




--
andy tomic
Back to top
Login to vote
Ken Slovak - [MVP - Outlo

External


Since: Oct 17, 2003
Posts: 2977



(Msg. 5) Posted: Thu Jul 09, 2009 6:35 pm
Post subject: Re: trap outbound mail to update subject [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

If you touch the item in the Outbox using code the send will be cancelled.

Application_ItemSend() will always fire, but sometimes it fires too late for
what you want to do, or some properties aren't changeable at that time.

If you want to handle things earlier, before the item gets to the Outbox
handle the Send() event on the item rather than the application-wide event.

--
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


"andy tomic" <andy.tomic.49c143e.DeleteThis@outlookbanter.com> wrote in message
news:andy.tomic.49c143e@outlookbanter.com...
>
> Thank you Alan and Ken.
>
> The addin is definitely triggered after the Application.ItemSend event.
>
>
> What I was thinking as a work around is to delay the message in the
> outbox for 1 min using a rule. Then manipulate the message with the
> code. My only shortfall is that I have not the knowledge to create a
> CUSTOM ACTION in the rules section.
>
> Is there a simple way to call the procedure once the email gets into
> the outbox ??
>
> Thanking you in advance
>
> Andy
>
>
>
>
> --
> andy tomic
Back to top
Login to vote
andy tomic

External


Since: Jul 15, 2009
Posts: 1



(Msg. 6) Posted: Wed Jul 15, 2009 6:05 am
Post subject: Re: trap outbound mail to update subject [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks Ken,

This is my problem. The Application_Send event fires TO EARLY. I need
the PROPRIETARY addin to fire first, it sets the category for the
mailitem. Then I can manipulate the subject based on the newly set
category, and save and resend the mailitem.

Also, the form based send() event fires to early as well.

I basically need the code to run after the PROPRIETARY addin runs. The
only way I have thought of is to put a 1min delay on the outbound mail
rule and perform a custom action. Unfortunately my programming skills
dont travel to the DLL world.

Any other ideas on how to accomplish this.

Thank you

Andy




--
andy tomic
Back to top
Login to vote
Ken Slovak - [MVP - Outlo

External


Since: Oct 17, 2003
Posts: 2977



(Msg. 7) Posted: Wed Jul 15, 2009 10:16 am
Post subject: Re: trap outbound mail to update subject [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

I have no idea what proprietary addin you're talking about.

Application.ItemSend() is the last event you'd get on outgoing items, so if
that's too early for you then you need to rethink your architecture.

--
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


"andy tomic" <andy.tomic.4a3547f.TakeThisOut@outlookbanter.com> wrote in message
news:andy.tomic.4a3547f@outlookbanter.com...
>
> Thanks Ken,
>
> This is my problem. The Application_Send event fires TO EARLY. I need
> the PROPRIETARY addin to fire first, it sets the category for the
> mailitem. Then I can manipulate the subject based on the newly set
> category, and save and resend the mailitem.
>
> Also, the form based send() event fires to early as well.
>
> I basically need the code to run after the PROPRIETARY addin runs. The
> only way I have thought of is to put a 1min delay on the outbound mail
> rule and perform a custom action. Unfortunately my programming skills
> dont travel to the DLL world.
>
> Any other ideas on how to accomplish this.
>
> Thank you
>
> Andy
>
>
>
>
> --
> andy tomic
Back to top
Login to vote
Display posts from previous:   
       Home -> Office -> Programming VBA All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Categories:
 Windows XP
 Windows Vista
 Windows Other
  Office
 Office Other
 Security
  • Home |
  • Shareware |
  • Windows Tips |
  • Hot Offers |
  • FREE Newsletters |
  • Arcade |
  • Forums |
  • eBooks |
  • About WUGNET |
  • Partners |
  • Contact

  • WUGNET Privacy Policy |
  • Link to WUGNET |
  • IT Support