【问题标题】:How to set the contact Email1DisplayName using the EWS Java API (Exchange Web Service)?如何使用 EWS Java API(Exchange Web 服务)设置联系人 Email1DisplayName?
【发布时间】:2013-05-21 08:40:54
【问题描述】:

我刚刚想出了如何设置标题(参见How to set the contact title using the EWS Java API (Exchange Web Service)?)。现在我正在尝试设置电子邮件 1 的显示名称。

如果我使用公开的 API Contact.getEmailAddresses().setEmailAddress(),显示名称会自动设置为与电子邮件地址相同(它会覆盖我的扩展属性)。

所以现在我正在尝试通过扩展属性设置完整的电子邮件信息。它几乎可以工作,除了当我查看通讯录时,名称和显示名称都是空的。

感觉这和Email1OriginalEntryId属性有关,不知道如何正确设置。

有什么想法吗?

我目前的尝试是这样的:

ExtendedPropertyDefinition propDef_PidLidEmail1DisplayName = new ExtendedPropertyDefinition(//
    UUID.fromString("00062004-0000-0000-C000-000000000046"), 0x8080, MapiPropertyType.String);

ExtendedPropertyDefinition propDef_PidLidEmail1AddressType = new ExtendedPropertyDefinition(//
    UUID.fromString("00062004-0000-0000-C000-000000000046"), 0x8082, MapiPropertyType.String);

ExtendedPropertyDefinition propDef_PidLidEmail1EmailAddress = new ExtendedPropertyDefinition(//
    UUID.fromString("00062004-0000-0000-C000-000000000046"), 0x8083, MapiPropertyType.String);

ExtendedPropertyDefinition propDef_PidLidEmail1OriginalDisplayName = new ExtendedPropertyDefinition(//
    UUID.fromString("00062004-0000-0000-C000-000000000046"), 0x8084, MapiPropertyType.String);

ExtendedPropertyDefinition propDef_PidLidEmail1OriginalEntryId = new ExtendedPropertyDefinition(//
    UUID.fromString("00062004-0000-0000-C000-000000000046"), 0x8085, MapiPropertyType.Binary);

ExchangeService mailbox = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
mailbox.setUrl(new URL("https://remote.domain.com/EWS/exchange.asmx").toURI());
ExchangeCredentials credentials = new WebCredentials("user.name", "pw", "domain");
mailbox.setCredentials(credentials);

Contact c = new Contact(mailbox);
c.setGivenName("GivenName");
c.setSurname("Surname");

//    c.getEmailAddresses().setEmailAddress(EmailAddressKey.EmailAddress1, new EmailAddress("AB12@B12.com"));

c.setExtendedProperty(propDef_PidLidEmail1AddressType, "SMTP");
c.setExtendedProperty(propDef_PidLidEmail1EmailAddress, "A12@B12.com");
c.setExtendedProperty(propDef_PidLidEmail1OriginalDisplayName, "A12@B12.com");
c.setExtendedProperty(propDef_PidLidEmail1DisplayName, "A12 B12 (A12@B12.com)");
//    c.setExtendedProperty(propDef_PidLidEmail1OriginalEntryId, ???);

c.save(WellKnownFolderName.Contacts);

【问题讨论】:

    标签: exchangewebservices ewsjavaapi


    【解决方案1】:

    难以置信,但经过将近一周的努力,我终于弄明白了。仅在 Exchange 2007 上测试。

    请注意,这仅在您像本示例中那样设置每个扩展属性并且不使用 Contact.getEmailAddresses().setEmailAddress() 时才有效。

    ExtendedPropertyDefinition propDef_PidLidEmail1DisplayName = new ExtendedPropertyDefinition(//
        UUID.fromString("00062004-0000-0000-C000-000000000046"), 0x8080, MapiPropertyType.String);
    
    ExtendedPropertyDefinition propDef_PidLidEmail1AddressType = new ExtendedPropertyDefinition(//
        UUID.fromString("00062004-0000-0000-C000-000000000046"), 0x8082, MapiPropertyType.String);
    
    ExtendedPropertyDefinition propDef_PidLidEmail1EmailAddress = new ExtendedPropertyDefinition(//
        UUID.fromString("00062004-0000-0000-C000-000000000046"), 0x8083, MapiPropertyType.String);
    
    ExtendedPropertyDefinition propDef_PidLidEmail1OriginalDisplayName = new ExtendedPropertyDefinition(//
        UUID.fromString("00062004-0000-0000-C000-000000000046"), 0x8084, MapiPropertyType.String);
    
    ExtendedPropertyDefinition propDef_PidLidEmail1OriginalEntryId = new ExtendedPropertyDefinition(//
        UUID.fromString("00062004-0000-0000-C000-000000000046"), 0x8085, MapiPropertyType.Binary);
    
    ExchangeService mailbox = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
    mailbox.setUrl(new URL("https://remote.domain.com/EWS/exchange.asmx").toURI());
    ExchangeCredentials credentials = new WebCredentials("user.name", "pw", "domain");
    mailbox.setCredentials(credentials);
    
    String FIRST = "First";
    String LAST = "Last";
    String FIRST_LAST = FIRST + " " + LAST; // "First Last"
    String EMAIL = "first.last@email.com";
    String DISPLAY_NAME = FIRST + " " + LAST + " (" + EMAIL + ")"; // "First Last (first.last@email.com)"
    
    Contact c = new Contact(mailbox);
    c.setGivenName(FIRST);
    c.setSurname(LAST);
    c.setFileAs(FIRST_LAST);
    
    // don't use this
    //    c.getEmailAddresses().setEmailAddress(EmailAddressKey.EmailAddress1, new EmailAddress(EMAIL));
    
    // Address book Name (seem to trigger the whole address book functionality)
    c.setSubject(FIRST_LAST);
    // Address book email address
    c.setExtendedProperty(propDef_PidLidEmail1OriginalDisplayName, EMAIL);
    // contact and address book display name
    c.setExtendedProperty(propDef_PidLidEmail1DisplayName, DISPLAY_NAME);
    
    c.setExtendedProperty(propDef_PidLidEmail1AddressType, "SMTP"); // constant
    c.setExtendedProperty(propDef_PidLidEmail1EmailAddress, EMAIL);
    
    // not needed after all, exchange sets this automatically
    //    c.setExtendedProperty(propDef_PidLidEmail1OriginalEntryId, ???);
    
    c.save(WellKnownFolderName.Contacts);
    
    for(Item item : mailbox.findItems(WellKnownFolderName.Contacts, new ItemView(1000)))
    {
      Contact result = (Contact) item;
    
      PropertySet propertySet = new PropertySet(BasePropertySet.FirstClassProperties);
      propertySet.add(propDef_PidLidEmail1AddressType);
      propertySet.add(propDef_PidLidEmail1EmailAddress);
      propertySet.add(propDef_PidLidEmail1OriginalDisplayName);
      propertySet.add(propDef_PidLidEmail1DisplayName);
      propertySet.add(propDef_PidLidEmail1OriginalEntryId);
    
      result = Contact.bind(mailbox, result.getId(), propertySet);
    
      LOGGER.info("count: " + result.getExtendedProperties().getCount());
    
      for(ExtendedProperty p : result.getExtendedProperties())
      {
        LOGGER.info(p.toString());
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-07
      • 2016-11-15
      • 2013-09-28
      • 2011-09-07
      相关资源
      最近更新 更多