Adding Custom Header on email

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

Adding Custom Header on email
 
franck DAMMANN




Posts: 41
Joined: 2021-01-26
Dear all,

I would need to add custom Header to outgoing emails (X-MyId=123 for instance). I tried to follow this previous https://www.add-in-express.com/forum/read.php?FID=5&TID=14156 but I'm facing an issue...

in my ProcessSend method (OutlookItemEventsClass.cs)I'm retrieving my mailItem
Outlook.MailItem mail = this.ItemObj as Outlook.MailItem;
but I'm not able to access
PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/X-MyId}", "123");


What I'm doing wrong ? does this propery is still available ?

Thanks for your help !
Franck.
Posted 18 Feb, 2021 11:26:29 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Franck,

To access that property at the run time, your add-in must be loaded in Outlook 2007 or above.
To access that property in your code you need to use interops for Office 2007 or above. Or, you can use late binding.

To replace interops, copy them from {Add-in Express}\Redistributables\Interops\Office {version} to {your project folder}\Interops replacing existing files. You may need to re-create the references.


Andrei Smolin
Add-in Express Team Leader
Posted 19 Feb, 2021 03:16:06 Top
franck DAMMANN




Posts: 41
Joined: 2021-01-26
Thanks Andrei,

in my projet {your project folder}\Interops Folder I had the following files:
Interop.VBIDE.dll
Interop.Office.dll
Interop.Outlook.dll

Whereas in the Office 2013 Interop folder (my minimum target) there are the following files:
Microsoft.Office.Interop.Outlook.dll
Office.dll

If I remove my existing projet Interop files and copy files from {Add-in Express}\Redistributables\Interops\Office I have an error while declaring Outlook.MailItem, there might be a different import to be done ? (currently using System.Runtime.InteropServices).

thanks,
Franck
Posted 19 Feb, 2021 05:45:24 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Franck,

You've used interops for Office 2000 created by Add-in Express. Remove these files and add new ones. Then remove references to old files and add references to new files. Note that a reference to Microsoft.Vbe.Interop.dll is only required if your code modifies VBA code; this isn't the case in 99.99% of addins.

There's a difference between Office 2000 interops and regular interops from Microsoft. After you replace the references, you may need to modify your code replacing a call SomeCollection.Item(anindex) with SomeCollection[anIndex]. This is the only change required. As far as I know this only applies to C#; VB.NET is not affected.


Andrei Smolin
Add-in Express Team Leader
Posted 19 Feb, 2021 05:53:50 Top
franck DAMMANN




Posts: 41
Joined: 2021-01-26
Andrei,

I have an error while calling
Outlook.MailItem mail = this.ItemObj as Outlook.MailItem;
mentioning Outlook is not found, missing directive or assembly reference...

I have this error in every reference to Oulook.MailItem, Outlook._application etc... in my code. Are you sure I do not need to import another Interop ?
Posted 19 Feb, 2021 06:04:50 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Add this using clause to these files:

using Outlook = Microsoft.Office.Interop.Outlook;

Similarly, you can refer to Office:

using Office = Microsoft.Office.Core;


Andrei Smolin
Add-in Express Team Leader
Posted 19 Feb, 2021 06:25:46 Top
franck DAMMANN




Posts: 41
Joined: 2021-01-26
Thanks Adnrei, works perfectly with this ;)
by the way another question concerning the SchemaName, when adding a new custom Header what is the meaning of the
http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}
added ? does this code have a specific meaning ? do I need to use my own code ?

Thanks again for your help !
Posted 19 Feb, 2021 06:33:14 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Using this is a must. You can customize "X-MyId" and "123"; see your first post.


Andrei Smolin
Add-in Express Team Leader
Posted 19 Feb, 2021 06:35:19 Top
franck DAMMANN




Posts: 41
Joined: 2021-01-26
Thanks ;-)
Regards from France !
Posted 19 Feb, 2021 06:41:10 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
You are welcome, Franck!


Andrei Smolin
Add-in Express Team Leader
Posted 19 Feb, 2021 08:41:20 Top