Alas… no that doesn’t work.
Okay I found a way around the problem but it’s a bit “hacky” so I’m not 100% happy about it, maybe if I explain what I am doing you might be able to figure out what the underlying problem is?
I decided to try saving the email as an “.eml” file so I can open it in Notepad to see what it looks like internally.
I noticed that sometimes the message looked like
From: My Name my.email@address.here on behalf of My Name
And sometimes it looked fine
From: My Name my.email@address.here
Often with pretty much the same email.
Here is what I am seeing when I save the email as an .eml
When it looks correct there will be two lines in the .eml file indicating who the sender is:
From: My Name my.email@address.here
Sender: My Name my.email@address.here
When it looks incorrect, the two lines look like:
From: My Name
Sender: My Name my.email@address.here
My “hack” to fix it was to read the .eml file into a string, find the first line that looks like
From: (some text) (followed by a line break)
In the above example, I know the sender is “My Name” and their address is my.email@address.here, so if I find the .eml’s “from” line looks like
From: My Name
then I replace that line with
From: My Name my.email@address.here
If it looks like anything else I’ll leave it alone.
If I change the From: line I then save it back to the original .msg file and that appears to resolve the problem.
Why, though, does changing the .SentRepresetingName and .SentRepresentingEmailAddress to null (or Nothing in VB) not work? I also tried using .SetStringPropertyValue to set the folowing values to empty strings:
MapiPropertyTag.PR_SENT_REPRESENTING_ADDRTYPE
MapiPropertyTag.PR_SENT_REPRESENTING_EMAIL_ADDRESS
MapiPropertyTag.PR_SENT_REPRESENTING_NAME
But that also doesn’t seem to work
The only thing that DOES appear to work is my dirty little hack converting the .msg to an .eml, changing the From line if necessary, and converting it back to a .msg again. Not ideal.