Help with 1st functional add-in - Not wanting you to do my job, but...

Add-in Express™ Support Service
That's what is more important than anything else

Help with 1st functional add-in - Not wanting you to do my job, but...
Clues on best way, components, events etc. 
Jason Chapman




Posts: 4
Joined: 2018-11-08
Pre-amble
For some this will seem a time waster, but I have spent some time reading the docs, doing some examples. I have a bunch of things I really want to achieve with the plug-ins, a lot to save me time and some that will be of benefit to my clients. I am not against paying for my time saved, or even subcontracting bits of the work, likewise happy to collect favors and just see how i can repay them over time :-). Pretty much anything I do will be presented, either as news or as mini-presentations at the ukDevGroup meetings I run monthly in London, UK for Delphi Developers. Anyone who helps me gets a plug. I'm happy to move the thread over to something like fiver or get into direct IM if the admins feel this is off topic and too rambling.

I need baby steps - I am a novice at this component set.... Everyones (even those that read, but don't reply) time is appreciated with this.

Current set of to-do's:
Grab subject of e-mail selected in folder list
This may not even need an add-in or an add-in may be able to facilitate it. I have have a little application that keeps track and records when the user changes focus in Windows, part of my timesheet recorder. It actually polls windows every second or so to get the application and the caption of the the active window. This is great if I have an e-mail opened as the caption is the subject. All my e-mails have the project number in the subject [projectnumber], so active caption gives a great correlation to project. Trouble is, when you are just in inbox or folder, the caption of the current form says <folder> <mailbox name> - Outlook, so I need to communicate the subject of the selected e-mail. So I can see a number of ways of doing this:
- Add-in communicates (tcp/IP / windows messages) with the app to tell it the name as the selected item change. Would need to give the app something that would allow the app to know which window it was from OR only send when it knows it is the active window.
- Doesn't need an add-in at all, just do xyz


Search Assistant and subject amend-er
Every e-mail gets a project put into the title [<project Number>], or as many projects that are relevant. Almost all inbound e-mails don't have a project number, so we need to work out which project it is and amend the subject. Typically we have a folder that is kind of our "todo" folder. To this end there may be a number of e-mails in there already that have been received already that have the project number. There are a couple of other folder that are kind of "done", so they may also have e-mails in the thread that have been allocated a project. Oftentimes a number of e-mails will come in all from the same thread or similar subjects that need allocating.
Goals
- to be able to work out the project number quickly
- amend the subject
- find other e-mails in project.
I currently do this by having 2 instances of Outlook open. Left hand side (LHS) is my todo folder with new e-mails coming in. Right Hand Side (RHS) is my search, group, workout what to do. I click on an e-mail in the LHS, and either copy word(s) from the subject or the project number if it is there. Paste into RHS search in current folder. Edit the e-mail subject to assign project numbers, read, broaden or reduce the search, work on and file some of them. It works well as it means if I haven't checked my e-mails for a day, I can action and file a large amount of e-mails quickly and efficiently. I also allocate catagories at this time (waiting for, do today, red....). If I can I will file the e-mails into the done folder.
- so I need to click on an e-mail (or it be the selected on) LHS
- have its subject in the RHS somehow, so I can click on a word / select a couple of words, select the project. Control area either in LHS, but probably RHS. Hotkey or button to make it happen, i.e. don't just change the RHS
- RHS - on selections of word etc, search in current folder
- allow me to quickly add a / the project number to an e-mail - if it has it already, then do nothing
- allow me to select multiple and do the above
- allow me to allocate project number to all

Folder Navigator and linker
On a clients site we have 1 folder for each of their clients (public folders) and a line of business system (LOBS). They have 5K clients. The LOBS needs to hold the client folder location and be able to tell outlook to goto that folder. When the client is set up, it need to have the option to create the folder and record it. Folder structure is ...\clients\a\abbot firstname accountnumber. When I am over an e-mail, have the ability to know which client it belongs to (LOBS can hold their e-mail address and also common to & froms). Ability to locate client in LOBS, one button file of e-mail... Also have a better "locate folder" than is in outlook, to be able to search for folder name containing and not need to explode each node out.
- So this is about parsing the public folder & caching the structure - I have done the iterate folder and due to time it takes, then caching seems sensible
- Passing a "command" from LOBS to add-in and vice versa
-- LOBS -> Add-in: goto folder pub:\...........\
-- Add-in -> LOBS: goto client
-- Add-in -> LOBS: What is the folder for <some info> and I'll offer to move the e-mail to that folder

So if you are still here - again thank you. I have had these ideas in my head for a long time, but just not managed to dedicate the time to action / research. I am not looking for complete system, but help / small code examples, direction in terms of "you'll need to use ......". Happy to take off forum etc. Happy for suggestions about your experience and how / how much if you want to engage for money. Happy to do some back and forth and if there is a possibility of making it a more formal arrangement, talk about it then.
Posted 20 Nov, 2018 06:28:14 Top
Andrei Smolin


Add-in Express team


Posts: 15827
Joined: 2006-05-11
Hello Jason,

As it looks now, we can solve most of these in the framework of the technical support service.

An entry point to the Outlook object model help is at https://docs.microsoft.com/en-us/office/vba/api/overview/outlook; check the below and then look in the Concepts section of the help reference.

#1. The Outlook object model provides the following objects:
- application - see the OutlookApp property of the add-in module
- the Explorers collection - OutlookApp.Explorers: it lists the Explorer windows opened in the current session; there are scenarios with no Explorer windows opened
- the Inspectors collection - OutlookApp.Inspectors: it lists the Inspector windows opened in the current session
- Explorer - either Explorers.Item(index) or OutlookApp.ActiveExplorer: represents an Explorer window
- Inspector - either Inspectors.Item(index) or OutlookApp.ActiveInspector: represents an Inspector window

To get the selected Outlook item, you get a Selection object via Explorer.Selection (this may fire an exception). If Selection.Count>0, selected items are accessible via Selection.Item(index). Get an item and use late binding to read its Subject property (I'd suggest that you expect an exception here as well). If you need to get more info about the item, use QueryInterface to cast it to _MailItem, _TaskItem, _ContactItem, etc. and then use early binding to get that info.

#2. An Outlook item such as _MailItem has the Parent property returning the parent folder of the MAPIFolder type. You use MAPIFolder.FullFolderPath (in latest Outlook versions) or construct the path by getting MAPIFolder.Name and MAPIFolder.Parent (which is a MAPIFolder or nil).

To modify a mail item, you set _MailItem.Subject := newSubject and then call _MailItem.Save().

To find non-processed emails in the folder, use Items.Restict as demonstrated at https://www.add-in-express.com/creating-addins-blog/2011/11/10/outlook-newmail-custom-solution/. Although this is a .NET-based article, I strongly recommend that you check it as it describes a working implementation (of finding new emails in Outlook); it also contains links to non-working ideas. Marshal.ReleaseComObject(someObject) in that article is an equivalent of someObject := nil in Delphi.

Create a custom pane and populate it with controls providing access to the functionality of your add-in. Check section Step #15 Adding Custom Task Panes in Outlook 2000-2019, see the PDF file in the folder {Add-in Express}\Docs on your development PC.

#3. Create a pane, show a list of clients, use a search box to filter the list, clicking an item should retrieve the folder to show and set Explorer.CurrentFolder := theFolderToShow.

You can invoke a public method defined on the add-in module:

var 
  oleIndex: OleVariant; 
begin 
  oleIndex := 'PROG_ID_OF_YOUR_ADD_IN'; 
  OleVariant(ExcelApp.COMAddIns.Item(oleIndex).Object_).YourMethod(); 
  // ... 


I believe I've missed some questions important for you; don't hesitate to point me to them!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 20 Nov, 2018 09:51:18 Top