title: VSTO Outlook Getting Email Address From Someone with same Domain
body: <p>In VSTO outlook 2013 addin I use this method to get the email address of the sender:</p>
  
  <pre><code>Inspector currentObject = Globals.ThisAddIn.Application.ActiveInspector();
  Object currentItem = currentObject.CurrentItem;
  MailItem message = currentItem as MailItem;
  string senderMailAddress = message.SenderEmailAddress;
  </code></pre>
  
  <p>This always works great except in one case.  I get a string that is their email address.  But if the sender is in the same domain as the person using the addin, I get a string that is a bunch of random characters, backslashes, and the email address without the domain in all caps.</p>
  
  <p>Example: 
  If the sender is person@example.com and the person using addin is also whatever@example.com (same domain)</p>
  
  <p>I'll get something like: 7GXaaJD\3x5FDd\PERSON rather than the normal email address string.</p>
  
  <p>I read somewhere in the docs (I can't seem to find it again) that when the sender is in the same domain, it will return this string rather than the normal email address, I'm not sure why but how can I get it into a normal email address even when they both belong to the same domain.  Or is there another way to circumvent this problem, as it makes no sense to me why it works the way to does.  If anyone happens to know the reasoning behind this I'd love to hear it.  But that's not my question.</p>
  
  <p>EDIT:</p>
  
  <p>Found this, <a href="https://msdn.microsoft.com/en-us/library/office/ff869674.aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/office/ff869674.aspx</a>
  Refers to MailItem.SenderEmailType property.  Which if EX is exchange server in same organization.  So I can test to see if I will get this werid string or a normal email string (if the type is SMTP).  </p>
  
  <p>The example seems to answer my question, but it's in VB, and I'm having some trouble to convert it to C#.  I see that I can get the AddressEntry from the MailItem object, and then use <code>x = GetExchangeUser()</code> and then do <code>x.PrimarySMTPAdress</code> to get the address.  But I'm not sure if this is correct either.</p>
  
  <p>If anyone has any information on SenderEmailType and dealing with exchange users in the same domain, any advice would help a lot.</p>
  
  <p>Thanks.</p>