简体   繁体   English

VSTO Outlook从具有相同域的某人获取电子邮件地址

[英]VSTO Outlook Getting Email Address From Someone with same Domain

In VSTO outlook 2013 addin I use this method to get the email address of the sender: 在VSTO Outlook 2013插件中,我使用此方法来获取发件人的电子邮件地址:

Inspector currentObject = Globals.ThisAddIn.Application.ActiveInspector();
Object currentItem = currentObject.CurrentItem;
MailItem message = currentItem as MailItem;
string senderMailAddress = message.SenderEmailAddress;

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. 但是,如果发件人与使用该插件的人位于同一域中,那么我会得到一个字符串,其中包含一堆随机字符,反斜杠和不带大写字母的域的电子邮件地址。

Example: If the sender is person@example.com and the person using addin is also whatever@example.com (same domain) 示例:如果发件人是person@example.com,并且使用插件的人也是what@example.com(同一域)

I'll get something like: 7GXaaJD\\3x5FDd\\PERSON rather than the normal email address string. 我会得到类似:7GXaaJD \\ 3x5FDd \\ PERSON的信息,而不是普通的电子邮件地址字符串。

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. 但这不是我的问题。

EDIT: 编辑:

Found this, https://msdn.microsoft.com/en-us/library/office/ff869674.aspx Refers to MailItem.SenderEmailType property. 找到了这个, https: //msdn.microsoft.com/en-us/library/office/ff869674.aspx引用MailItem.SenderEmailType属性。 Which if EX is exchange server in same organization. 如果EX是同一组织中的交换服务器,则该选择。 So I can test to see if I will get this werid string or a normal email string (if the type is SMTP). 因此,我可以进行测试以查看是否会得到该字符串或正常的电子邮件字符串(如果类型为SMTP)。

The example seems to answer my question, but it's in VB, and I'm having some trouble to convert it to C#. 该示例似乎可以回答我的问题,但是它在VB中,并且在将其转换为C#时遇到了一些麻烦。 I see that I can get the AddressEntry from the MailItem object, and then use x = GetExchangeUser() and then do x.PrimarySMTPAdress to get the address. 我看到可以从MailItem对象获取AddressEntry,然后使用x = GetExchangeUser() ,然后执行x.PrimarySMTPAdress以获取地址。 But I'm not sure if this is correct either. 但是我不确定这是否正确。

If anyone has any information on SenderEmailType and dealing with exchange users in the same domain, any advice would help a lot. 如果有人拥有有关SenderEmailType的任何信息并与同一域中的交换用户打交道,那么任何建议都将大有帮助。

Thanks. 谢谢。

If SenderEmailType == "SMTP", just use SenderEmailAddress . 如果SenderEmailType ==“ SMTP”,则只需使用SenderEmailAddress

If SenderEmailType == "EX", use MailItem.Sender.GetExchangeUser().PrimarySmtpAddress . 如果SenderEmailType ==“ EX”,请使用MailItem.Sender.GetExchangeUser().PrimarySmtpAddress Be prepared to handle nulls and exceptions. 准备处理null和异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM