|
Pino Carafa
Posts: 162
Joined: 2016-09-28
|
Please note that the Add-in I am working on is, or is at least based on, a legacy Add-in that has already been in use and cannot easily be changed.
The problem in a nutshell. When composing a message we allow the user to interact with our Case Management system, and we can then set User Properties in the MailItem to represent their choices. And you guessed it, one of our clients has a contact who is using a Mail Client that cannot handle TNEF mail formats so they're complaining about winmail.dat attachments. We cannot simply strip out those User Properties when sending the mail, because we may want to refer to them again when the user, for example, wants to view the message in their Sent Items or whatnot.
And as I said, we don't want to have to change too much in our Add-in. For example, clients have used this for years now, so their Inboxes and their Sent Items folders will be full of MailItems in which we have set these User Properties.
So I found this:http://stackoverflow.com/questions/27269622/tag-outlook-mailitem-with-id-number-before-send-without-causing-tnef-rtf-send/39744524
One suggestion made there was to use the MailItem.PropertyAccessor.SetProperty method to set the property, but I don't understand it well enough to know what I need to do exactly. Everywhere where I see this used, the developer refers to some sort of schema "http" location. How do I use it to set our "CaseReference" property? And even if somebody can tell me what "http" string to use to set a Property with the name "CaseReference", when the user subsequently opens the Sent item from their Sent Items folder, can I still access that property through the same .UserProperties("CaseReference") code that we have always used there?
I suspect that you cannot set properties through MailItem.PropertyAccessor.SetProperty in such a way that you can elsewhere refer to them through the MailItem.UserProperties collection. It would be great if I were wrong, but I'm afraid I'm not, so then....
I could still use the .UserProperties.Add function to add our "CaseReference" property. But then how do I stop it from sending the mail as TNEF? Well, one suggestion I found was to use MailItem.PropertyAccessor.SetProperty as follows using ItemSend:
MailItem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8582000B", false)
Ok - that will ensure that the sent mail is not in TNEF format, but that means that the mail going out doesn't have User Properties in it. Does that mean that when the user subsequently tries to open it from their Sent Items they won't have access to that User Property either? That isn't going to work for us.
So, in short, what I would be looking for is some advice on which approach might work for us, and if any of the above are going to work, some code examples on how to use procedures like PropertyAccessor.SetProperty correctly in VB.NET
Would it be appropriate to add a trimmed down VB.NET project here that somebody could add the lines of code we would require into. It would be a code sample that Andrei would be familiar with as he has been very helpful to us in the past week or so regarding another issue, but until now we have only communicated through e-mail... |
|
Posted 28 Sep, 2016 08:39:23
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 19011
Joined: 2006-05-11
|
Hello Pino,
Sending without userproperties is a must if you need to send without the winmail.dat attachment. I suggest that you remove the userproperties in the ItemSend event and restore them when the item is put to the target folder: this is accompanied with the ItemAdd event of the Items collection of that folder. In Add-in Express this event is mapped to the ItemAdd method of the Outlook Items (not Item!) Events class; see the Add New Item dialog of your add-in project.
To get the target folder you retrieve the MailItem.SaveSentMessageFolder property in the ItemSend event. Note that the email will be put in this folder only if the "Save copies of messages in the Sent Items folder" flag is set; see File | Options | Mail | Save Messages group. To the best of my knowledge, it isn't possible to check/modify this flag programmatically.
To restore the properties, you would need to know if an email fallen to the Sent Items folder is *the* email. I suggest using this approach: add a custom item to Internet headers, retrieve the internet headers of the email added to the SentItems folder, parse the headers, find your header, and use the information it provides to recreate user properties. This schema allows dealing with the user copying a lot of emails to that folder.
To add a custom item to Internet headers, you use
MailItem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/X-{element name such as MyId}", "{some value such as 123}"):
myMail.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/X-MyId}", "123")
Open an email sent/received, click File | Info | Properties, look for "X-MyId=123" in the Internet headers text box. You retrieve internet headers using myMail.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/X-MyId}"; the result is an object - cast it as required.
What do you think?
Andrei Smolin
Add-in Express Team Leader |
|
Posted 29 Sep, 2016 06:29:27
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 19011
Joined: 2006-05-11
|
Andrei Smolin writes:
I suggest using this approach: add a custom item to Internet headers, retrieve the internet headers of the email added to the SentItems folder, parse the headers, find your header, and use the information it provides to recreate user properties.
A correction: add a custom item to Internet headers in the ItemSend event.
Andrei Smolin
Add-in Express Team Leader |
|
Posted 29 Sep, 2016 06:33:19
|
|
Top
|
|
Pino Carafa
Posts: 162
Joined: 2016-09-28
|
Thanks a million, Andrei, I shall give that a spin. |
|
Posted 29 Sep, 2016 09:58:50
|
|
Top
|
|
Pino Carafa
Posts: 162
Joined: 2016-09-28
|
Well Andrei that looks very promising indeed. I don't think I even need to worry about doing anything in the ItemSend event; it looks like I can simply use .PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/X-MyId}", "123") while the user is composing the e-mail. I tried that just now and sent the e-mail to myself, and the header is present in the copy in my inbox. In my "Sent Items" folder the "headers" box is blank, but if I drag the .msg onto my desktop and open it with Notepad I can find the header I added amongst all the gobbledygook, so that is looking good, too! |
|
Posted 29 Sep, 2016 11:29:49
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 19011
Joined: 2006-05-11
|
Glad to be of help!
Andrei Smolin
Add-in Express Team Leader |
|
Posted 30 Sep, 2016 04:26:08
|
|
Top
|
|
Pino Carafa
Posts: 162
Joined: 2016-09-28
|
Hello Andrei,
Found a few interesting permutations on this, but I don't think any of them have anything to do with Add-in Express.
The functionality works perfectly when I'm simply composing and sending an e-mail. I used .PropertyAccessor.SetProperty to set the value, and I read them in the .ItemAdd event handler for the Sent Items. Easy and it works well.
But of course somebody had to throw a spanner in the works. Some clients insist of having their items sent to them Signed and Encrypted. Now I was able to use Redemption through a bunch of contortions. But even though I was eventually able to get my hands on the RDOItem for the item that was sent, get a decrypted version of same as another RDOItem, but I was unable to make this work to get the property I set. And when I used .SaveAs to save the item to my hard drive and I opened the resulting .msg with Notepad I couldn't find the property amongst the text in there either, like I was able to do with the unencrypted ones.
I did manage to get it resolved, however, by using an Shared object to store some info that I refer to if the message is encrypted. Bit clunky, but it works. If you have a better suggestion I would greatly appreciate it, but no worries either way!
Just one final question, just in case you might have an answer to this, but you wouldn't know a good example of a freely downloadable Mail Client that you are certain of that can't handle "winmail.dat" attachments? I'm trying to send test mails to our customer's client who has such an e-mail client, but responses from them are rarer than hens' teeth. |
|
Posted 30 Sep, 2016 14:41:18
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 19011
Joined: 2006-05-11
|
Hello Pino,
Many thanks for posting these details!
Pino Carafa writes:
Just one final question, just in case you might have an answer to this, but you wouldn't know a good example of a freely downloadable Mail Client that you are certain of that can't handle "winmail.dat" attachments?
I don't know such a mail client.
Andrei Smolin
Add-in Express Team Leader |
|
Posted 03 Oct, 2016 04:53:25
|
|
Top
|
|
Pino Carafa
Posts: 162
Joined: 2016-09-28
|
No worries. I tried Thunderbird but lo and behold it was perfectly happy :-) |
|
Posted 03 Oct, 2016 08:55:40
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 19011
Joined: 2006-05-11
|
)))
Andrei Smolin
Add-in Express Team Leader |
|
Posted 03 Oct, 2016 09:09:27
|
|
Top
|
|