trap outbound mail to update subject

Status
Not open for further replies.
A

andy tomic

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

;) . 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
 
A

Alan Moseley

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
> ;) . 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
>
 
K

Ken Slovak - [MVP - Outlook]

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.

"Alan Moseley" <AlanMoseley> 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.
>
 
A

andy tomic

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
 
K

Ken Slovak - [MVP - Outlook]

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.

"andy tomic" <andy.tomic.49c143e@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
 
A

andy tomic

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
 
K

Ken Slovak - [MVP - Outlook]

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.

"andy tomic" <andy.tomic.4a3547f@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
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
M Trap email send event Outlook VBA and Custom Forms 7
J Addin to trap email item open Outlook VBA and Custom Forms 2
J Addin to trap email item open Outlook VBA and Custom Forms 2
J Edge + TMG 2010 No email inbound/outbound and cannot telnet to port 25 on TMG Exchange Server Administration 0
Aussie Outlook 365 Rule runs manually but returns the error code "an unexpected error has occurred" when incoming mail arrives Using Outlook 0
D ISOmacro to extract active mail senders name and email, CC, Subject line, and filename of attachments and import them into premade excel spread sheet Outlook VBA and Custom Forms 2
witzker Outlook 2019 Macro to answer a mail with attachments Outlook VBA and Custom Forms 2
D Outlook 2003 Mail Fails Using Outlook 1
Cathy Rhone Mail merge error message Using Outlook 2
R Sent emails show iCloud mail account not the alias Using Outlook 2
D Advanced e-Mail search on from/to contact group only searches for first 20 contacts in group Using Outlook 0
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 4
P Importing other e-mail accounts into Outlook Using Outlook 1
lcarpay Stay in the mail folder pane after ctrl-1 Using Outlook 1
O Exchange Sync period only (e.g. last years mail) Using Outlook 0
F Excel VBA to move mails for outlook 365 on secondary mail account Outlook VBA and Custom Forms 1
M Convertor for Outlook Express Mail Store (.dbx) to Outlook Mail Store (.pst) Using Outlook 0
T vba extract data from msg file as attachment file of mail message Outlook VBA and Custom Forms 1
J E-mail held in Outbox while Minimized Using Outlook 3
G Forward email body to other mail list directly from Exchange server Exchange Server Administration 1
T Outlook creates a copie of every mail I send Using Outlook.com accounts in Outlook 4
N Please advise code received new mail Using Outlook 0
M Outlook 2010 How could I globally redesign an outlook template form/region/inspector template used to display mail lists or an individual mails? Outlook VBA and Custom Forms 0
A How to stop user form from disapearing once mail window is closed? Outlook VBA and Custom Forms 0
M Outlook, send to > mail recipient - results in plain text email Using Outlook 1
R How to Sync *all* Google Workspace Mail Folders with Outlook 2019 (MS365) Using Outlook 3
S Outlook VBA How to adapt this code for using in a different Mail Inbox Outlook VBA and Custom Forms 0
E Having some trouble with a run-a-script rule (moving mail based on file type) Outlook VBA and Custom Forms 5
S Outlook email to configure setup for each mail Outlook VBA and Custom Forms 1
L Correct E-Mail Pulling Wrong Mail Using Outlook 5
S Outlook mail adressing stops after first match in GAL Using Outlook 0
P Outlook 2013 All imported Mail Rules in error when imported into new profile Using Outlook 5
S Outlook Macro to send auto acknowledge mail only to new mails received to a specific shared inbox Outlook VBA and Custom Forms 0
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
MrMayor SENT mail not reloading to top?? Using Outlook 4
Terry Sullivan Sender Field Displays My E-Mail Address, Not My Name Using Outlook 1
ThinkToday Calculate reply time of outlook mail Using Outlook 1
B Outlook 2010 Opening Mail Attachment Using Outlook 2
e_a_g_l_e_p_i Is it possible it set the fonts used to read incoming mail Using Outlook 25
D Mail in Sent Items Gone Using Outlook 12
M Managing Gmail "All Mail" sync issues with IMAP Using Outlook 1
GregS Outlook 2016 Sent Mail absent from Sent Mail or Sent Items Folders Using Outlook 4
GregS Why is Outlook 2016 mail in Outlook.com? Using Outlook 1
S Outlook not receiving mail Using Outlook 1
Commodore Outlook (2013) issues with icloud.com mail Using Outlook 0
GregS Outlook 2016 iPhone won't download Outlook 2016 Mail. Using Outlook 0
A Arthur needs help with 2007 Outlook e-mail Using Outlook.com accounts in Outlook 3
oliv- How to distinguish whether mail is incoming or outgoing? Outlook VBA and Custom Forms 2
W Receiving mail for account that has been deleted Using Outlook 2
H In outlook 365 POP mail Inbox, email takes a long time or never arrives. Using Outlook 1

Similar threads

Top