从 MeetingItems/ReportItems 中提取发件人地址电子邮件

问题描述 投票:0回答:3

我正在尝试编写一个程序来查找我的电子邮件。我在编写返回发件人电子邮件地址的函数时遇到问题。无论它是什么类型的消息。 我发现功能:

def return_sender(msg):
    if msg.Class == 43
        if msg.SenderEmailType == "EX":
            if msg.Sender.GetExchangeUser() != None:
                return msg.Sender.GetExchangeUser().PrimarySmtpAddress
            else:
                return msg.Sender.GetExchangeDistributionList().PrimarySmtpAddress
        else:
            return msg.SenderEmailAddress

类 43 是 MailItem,但例如如何从类 53 = MeetingItem 获取发件人地址?

msg.Sender

它返回属性错误。

msg.SenderEmailAddress

返回:

/O=EXCHANGELABS/OU=EXCHANGEADMINISTRATIVEGROUP(FYDIBOHF23SPDLT)/CN=RECIPIENTS/CN=6F467C825619482293F429C0BDE6F1DB-

是否有任何方法可以从 MailItem 以外的消息类型获取发件人?以及如何查看 Outlook 的消息类型 谢谢你

python email outlook office-automation sender
3个回答
0
投票

您需要将 Exchange 格式的 X509 电子邮件地址转换为 SMTP 电子邮件地址。请参阅如何:将基于 Exchange 的电子邮件地址转换为 SMTP 电子邮件地址一文了解更多相关信息。

这是可能的方法之一:

/// <summary> 
/// Finds the SMTP addres based on an exchange string inside an outlook contact 
/// </summary> 
/// <param name="">Has to be an exchange address string</param> 
/// <returns></returns> 
private string GetSMTPAddressViaOutlookObjectModel(string exchangeAddress) 
{ 
    // Start with an empty string 
    var address = string.Empty; 
 
    // Create a recipients with the exchange address 
    // E.g. ..... 
    Outlook.Recipient recipient = Module.OutlookApp.Session.CreateRecipient(exchangeAddress); 
 
    // Resolve the recipient 
    recipient.Resolve(); 
 
    // When the recipient is resolved 
    if (recipient.Resolved) 
    { 
        // Get the user behind the resolved address 
        Outlook.ExchangeUser user = recipient.AddressEntry.GetExchangeUser(); 
 
        // If the user is found 
        if (user != null) 
        { 
            // set the address to the primary SMTP address of the exchange user 
            address = user.PrimarySmtpAddress; 
            // Release the user object 
            Marshal.ReleaseComObject(user); 
        } 
 
        // Release the recipient object 
        Marshal.ReleaseComObject(recipient); 
    } 
 
    // return the address 
    return address; 
} 

0
投票

您可以使用

ReportItem/MeetingItem.PropetyAccessor.GetProperty
检索任何 MAPI 属性,您只需要知道该属性的 DASL 名称即可。例如。
PR_SENT_REPRESENTING_SMTP_ADDRESS
(特定商品可能有也可能没有)是
"http://schemas.microsoft.com/mapi/proptag/0x5D02001F"
。使用 OutlookSpy 查看报告/会议项目(我是其作者) - 选择有问题的项目,单击 OutlookSpy 功能区上的 IMessage 按钮,选择您需要的属性,查看 DASL 编辑框。


0
投票

以下解决了电子邮件=的问题 /O=EXCHANGELABS/OU=交换管理组(FYDIBOHF23SPDLT)/CN=收件人/CN=6F467C825619482293F429C0BDE6F1DB-

定义常量

SMTP_PROPERTY =“http://schemas.microsoft.com/mapi/proptag/0x39FE001E”

def get_smtp_email(收件人): property_accessor = 接收者.PropertyAccessor 尝试: # 使用指定属性检索 SMTP 电子邮件地址 smtp_address = property_accessor.GetProperty(SMTP_PROPERTY) 返回smtp_地址 除了异常 e: print(f"访问 SMTP 电子邮件地址时出错:{e}") # 如果特定属性不可用,则回退到使用收件人的地址属性 返回收件人地址

© www.soinside.com 2019 - 2024. All rights reserved.