We have a solution where users save email messages from their outlook in MSG format. Then there is another process that picks up these files, reads (through Aspose) the data inside and updates metadata e.g. From/To/Subject etc.
This worked fine mostly until:
we found a few emails with the from address being read like below:
Firstname Lastname </O=domain/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPEINTS/CN=UserId>
instead of
Firstname Lastname userid@domain.com.au
We were able to reproduce this consistently when we saved email messages from the Sent Items (in Outlook). It works perfectly fine when we saved emails from the Inbox
Any idea why this is happening and how this could be resolved would be much appreciated.
Hi,
Thank you for using Aspose.Email.
The format of the email address that you have got is referred to as Exchange format. It is an expected behavior if the message does not have address in smtp format. If a message’s SenderAddressType is equal to “EX” i.e. Exchange, the SenderEmailAddress property will return Sender’s SMTP address instead of PR_SENDER_EMAIL_ADDRESS property. Moreover, PR_SENDER_EMAIL_ADDRESS may be missing as well in some cases.
If message contains SMTP format address, you could use the following code to get the proper email address:
string s = mapi.TryGetPropertyString(MapiPropertyTag.PR_SENDER_EMAIL_ADDRESS);
Hi,
I would like to further share with you that you can use the MapiNamedProperty in some cases as a work around to get the From address, as follow:
foreach (MapiNamedProperty namedProperty in mapiMessage.NamedProperties.Values)
{
if (namedProperty.Oom == "InetAcctName")
{
string senderEmail = namedProperty.GetString();
}
}
Hi Kasif,
Thanks for your posts. I tried your solution but this did not work.
I have the msg file in a filestream.
The code is now like this :
MapiMessage mapiMessage = MapiMessage.FromStream(_msgStream);
string From = MapiMessage.TryGetPropertyString(MapiPropertyTag.PR_SENDER_EMAIL_ADDRESS);
Anything I am doing incorrect here ?
If any help I would explain that again: The user saves and msg file from Outlook (can be either inbox or sent items). Once saved, a totally independent service picks up the msg file as a filestream, and parses through the meta data to update the database. I tried your work around through the code above, and got the exact same result I was getting before.
Any ideas ?
Thanks
Actually it made it worse. Now emails saved from the Inbox are coming up with the wrong address too.
Hi,
Hi Kashif,
Thanks for replying. I have attached the two msg files one working and the other not working. They are essentially the same email, sent to myself, the one not working was saved from my Sent Items in Outlook.
Looking forward to hear back from you soon.
Shah
Hi Shah,
Hi Kashif,
Thanks for your reply.
I understand now how to check if information is missing. But that does not solve my problem. Would be helpful if you can suggest how to extract the sender’s name/email address from the file. Is there any way, either by reading the file somewhat different or making changes on my Outlook/Exchange I can get the sender’s email address in the right format ?
I do not intend to install Outlook APIs or AD queries on my server, where this service is running. That was our main intention of purchasing Aspose, to not install Outlook on my server.
Hi,
Thank you for the feedback.
As you told earlier that messages are saved from Outlook (which I assume is configured to your Exchange server), so it seems something to be at Outlook/Exchange server end. Can you please reconfirm to us that your Outlook is configured with Exchange server and messages are saved from Outlook’s sent item folder locally?
Also, for your requirements, you can also use Aspose.Email API to fetch the messages/information from the Exchange server’s Sent Items folder and check its “From” field, in addition to saving, as follow:
const string mailboxUri = “you exchangURI here”;
const string domain = @"";
const string username = @"username";
const string password = @"password";
NetworkCredential credential = new NetworkCredential(username, password, domain);
using (ExchangeWebServiceClient client = new ExchangeWebServiceClient(mailboxUri, credential))
{
// Call ListMessages method to list messages info from Inbox
ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.SentItemsUri);
/// Loop through the collection to get Message URI
foreach (ExchangeMessageInfo msgInfo in msgCollection)
{
string strMessageURI = msgInfo.UniqueUri;
MailMessage msg = client.FetchMessage(strMessageURI);
Console.WriteLine(msg.From);
msg.Save(msg.Subject + ".msg", MailMessageSaveType.OutlookMessageFormatUnicode);
}
}
We request you to please give this code a try at your end with your Exchange server and let us know if it fetches the “From” field properly. There are some other articles also available in our online documentation section that you can refer to for further programming samples using Exchange Server.
In case this is not helpful, please share your Exchange Server information with us in addition to any other information that can be of further help to us.
Hi Shah,
Hi Kashif,
Thanks for your reply. I appreciate you escalating the issue. We are looking forward to hear back with a suitable solution.
Hi Shah,
Hi Shah,
Hi Kashif,
It is sad to see that we paid so much for a system, that does not solve our problem. As I said earlier to you and to Adam, if we needed to query the exchange server to get information, we would not need to buy Aspose, we could just do that ourselves, and avoid buying an expensive software with limitations.
The unfortunate bit is the limitation of your program is not mentioned a disclaimer that it does not work on certain cases. If we read that we possibly would not have paid for an expensive product.
Not a very happy customer.
Hi Shahriar,
Hi Shahriar,