Outlook: Problem generating X-Header

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

Outlook: Problem generating X-Header
when setting an individual x-header the SetProperties-method notifies an System.ArgumentException 
André Gerards




Posts: 10
Joined: 2017-11-15
Hello everybody,

I'm using VS2017 with VB.net and Add-in Express for Office and .NET.

I'm trying to add a X-Header to my outgoing mail.
I've added the ADX Outlokk Item Events Class and in the ItemSend-Event I'm e.g. able to add text to the subject.

Now I've tried to add an X-Header with the following code:


Private Sub NB_OutlookAppEvents_ItemSend(sender As Object, e As ADXOlItemSendEventArgs) Handles NB_OutlookAppEvents.ItemSend
	'my mail
	Dim mlItm As Outlook.MailItem = TryCast(e.Item, Outlook.MailItem)

	If Not IsNothing(mlItm) Then
		'subject
		Dim addToSubject As String = " - nice world"
		If Not mlItm.Subject.Contains(addToSubject) Then
			mlItm.Subject += addToSubject
		End If

		'body
		Dim addToBody As String = "my text"
		If Not mlItm.Body.EndsWith(addToBody) Then
			mlItm.Body += addToBody
		End If

		'x-header
		Dim myProp As String = "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/X-MyHeader"
		Dim myValue As String = "4711"
		mlItm.PropertyAccessor.SetProperties(myProp, myValue)

	End If

End Sub


I'm getting the following exeption:
System.ArgumentException
HResult=0x80070057
Nachricht = Der Vorgang konnte nicht abgeschlossen werden. Mindestens ein Parameterwert ist ungültig.
[my translation] Message = The process was not able to finish, At least on parameter value ist not valid.

Any ideas?

Thanks and kind regards
André
Posted 21 Nov, 2017 10:59:55 Top
Andrei Smolin


Add-in Express team


Posts: 14671
Joined: 2006-05-11
Hello André,

Does it work if you comment out the code that modifies the body and subject? If yes, I suggest that you save the item after you modify it. If the issue occurs because you modify the body; check if this works with a plain text email.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 22 Nov, 2017 03:25:50 Top
André Gerards




Posts: 10
Joined: 2017-11-15
Hello Andrei,
no, nothing changes, the same behaviour like before?!
Regards, André
Posted 22 Nov, 2017 04:09:00 Top
Andrei Smolin


Add-in Express team


Posts: 14671
Joined: 2006-05-11
Hello André,

This should work. Try to invoke this code in a simple add-in. Try to restart the machine, turn all other COM add-ins off, and repair the message store. If you use PST, consider repairing it using ScanPst.exe; on my machine it is located in C:\Program Files (x86)\Microsoft Office\root\Office16\. If this is an Exchange mailbox, consider deleting the .OST file as Microsoft recommends at https://support.microsoft.com/en-us/help/983036/the-scanost-exe-tool-is-not-available-starting-with-outlook-2010. Is this an IMAP Folders store created by e.g. GMail or HotMail?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 22 Nov, 2017 06:30:19 Top
André Gerards




Posts: 10
Joined: 2017-11-15
Hello Andrei,

I've unregistered each COM-Add-In, cleaned up the registry (CCleaner) checked and repaired the PST-File, restarted the computer and ... the same problem :(
My system is Win10 Pro (x64, Version 1709, Build 16299.64) with VS2017 (15.4.4) and Add-In-Express (8.8.4430)
My example-account is an IMAP/SMTP-account manually configuerd account at the german hoster strato.de.

The error occurs before the Mail is send. If I continue the procedure first Outlook fires an error-message and then the mail is sent, but without X-Header.

Is there a way to send you my sample-project so that you can have a look on it?

Thanks,
André
Posted 22 Nov, 2017 10:05:21 Top
Andrei Smolin


Add-in Express team


Posts: 14671
Joined: 2006-05-11
André,

Find the support email address in {Add-in Express installation folder}\readme.txt. Please make sure you email contains a link to this topic. I'll look into the project tomorrow.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 22 Nov, 2017 10:07:20 Top
André Gerards




Posts: 10
Joined: 2017-11-15
Hi Andrei,

I tried a little VBA-Event, an this works without any problems !?!?!?!?


Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  Dim pa As Outlook.PropertyAccessor
  Set pa = Item.PropertyAccessor
  pa.SetProperty "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/X-TestHeader", "HereWeAre"
  Set pa = Nothing
End Sub


Regards,
André
Posted 23 Nov, 2017 03:12:33 Top
Andrei Smolin


Add-in Express team


Posts: 14671
Joined: 2006-05-11
Hello André,

In your code you call SetProperties(), not SetProperty().

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 23 Nov, 2017 04:45:34 Top
Andrei Smolin


Add-in Express team


Posts: 14671
Joined: 2006-05-11
Also I strongly suggest *not* using message boxes while debugging an add-in: a message box causes an events flow which doesn't occur if no message box is shown. This may hide a real issue and produce a different one instead.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 23 Nov, 2017 04:47:45 Top
André Gerards




Posts: 10
Joined: 2017-11-15
oh f... thats too simple :)
Thank you very much,
André
Posted 23 Nov, 2017 05:01:45 Top