PST 파일에서 Outlook 연락처 관리
연락처 생성, 저장 및 읽기
Aspose.Email을 사용하면 Outlook 연락처를 생성하고 처리할 수 있습니다. MapiContact 클래스는 Outlook 연락처를 생성하고 조작하는 데 필요한 모든 연락처 관련 속성을 제공합니다. 이 문서는 해당 클래스를 사용하여 Outlook 연락처를 생성, 저장 및 읽는 방법을 보여줍니다. MapiContact 클래스.
Outlook 연락처 생성 및 저장
연락처를 생성하고 디스크에 저장하려면, 다음 단계를 따르세요:
- 새 객체를 인스턴스화합니다 MapiContact 클래스.
- 연락처 속성 정보를 입력합니다.
- 사진 데이터를 추가합니다(있는 경우).
- 연락처를 MSG 또는 VCard 형식으로 저장합니다.
다음 코드 조각은 Outlook 연락처를 생성하고 저장하는 방법을 보여줍니다:
import aspose.email as ae
data_dir = "path/to/data/directory"
contact = ae.mapi.MapiContact()
contact.name_info = ae.mapi.MapiContactNamePropertySet("Bertha", "A.", "Buell")
contact.professional_info = ae.mapi.MapiContactProfessionalPropertySet("Awthentikz", "Social work assistant")
contact.personal_info.personal_home_page = "B2BTies.com"
contact.physical_addresses.work_address.address = "Im Astenfeld 59 8580 EDELSCHROTT"
contact.electronic_addresses.email1 = ae.mapi.MapiContactElectronicAddress("Experwas", "SMTP", "BerthaABuell@armyspy.com")
contact.telephones = ae.mapi.MapiContactTelephonePropertySet("06605045265")
contact.personal_info.children = ["child1", "child2", "child3"]
contact.categories = ["category1", "category2", "category3"]
contact.mileage = "Some test mileage"
contact.billing = "Test billing information"
contact.other_fields.journal = True
contact.other_fields.private = True
contact.other_fields.reminder_topic = "Test topic"
contact.other_fields.user_field1 = "ContactUserField1"
contact.other_fields.user_field2 = "ContactUserField2"
contact.other_fields.user_field3 = "ContactUserField3"
contact.other_fields.user_field4 = "ContactUserField4"
# Add a photo
with open(data_dir + "Desert.jpg", "rb") as file:
buffer = file.read()
contact.photo = ae.mapi.MapiContactPhoto(buffer, ae.mapi.MapiContactPhotoImageFormat.JPEG)
# Save the Contact in MSG format
contact.save(data_dir + "MapiContact_out.msg", ae.mapi.ContactSaveFormat.MSG)
# Save the Contact in VCF format
contact.save(data_dir + "MapiContact_out.vcf", ae.mapi.ContactSaveFormat.V_CARD)
VCF 형식 버전 3으로 연락처 저장
VCF 형식 버전 3으로 연락처를 저장하려면, VCardSaveOptions 클래스.
- 새 인스턴스를 생성합니다 VCardSaveOptions 클래스.
- VCardSaveOptions 객체의 version 속성을 VCardVersion.V30으로 설정합니다. 이렇게 하면 vCard 버전이 3.0이 됩니다.
- 다음을 호출합니다. 저장 MapiContact 객체의 메서드로, 파일 이름 "contact.vcf"와 VCardSaveOptions 객체를 매개변수로 전달합니다. 이렇게 하면 지정된 파일 이름과 옵션으로 vCard 파일이 저장됩니다.
다음 코드 조각은 VCF 형식 버전 3으로 연락처를 저장하는 방법을 보여줍니다:
import aspose.email as ae
contact = ae.mapi.MapiContact()
contact.name_info = ae.mapi.MapiContactNamePropertySet("Bertha", "A.", "Buell")
options = ae.personalinfo.vcard.VCardSaveOptions()
options.version = ae.personalinfo.vcard.VCardVersion.V30
contact.save("contact.vcf", options)
MSG 또는 VCard 파일에서 연락처 로드
다음은 MapiContact 클래스를 사용하면 Outlook MSG와 VCard 형식의 연락처를 모두 로드할 수 있습니다.
MSG에서 연락처를 로드하려면, 아래 코드 예제를 사용하십시오:
VCard에서 연락처를 로드하려면, 다음 코드 예제를 사용하십시오:
지정된 인코딩으로 연락처 로드
다음 코드 조각은 지정된 인코딩으로 vcard에서 연락처를 로드하는 방법을 보여줍니다.
사용자 정의 문자 인코딩으로 VCard 파일 저장
vCard 파일을 저장할 때 문자 인코딩을 정의하여 비ASCII 문자와의 호환성을 보장할 수 있습니다. 예를 들어, 클래스의 preferred_text_encoding 속성을 설정하면 VCardSaveOptions 객체를 "utf-8"로 설정하면 비ASCII 텍스트를 올바르게 인코딩합니다. 이 기능은 다국어 연락처 데이터를 처리할 때 특히 유용합니다. 아래는 사용자 정의 문자 인코딩으로 vCard 파일을 구성하고 저장하는 예시입니다:
import aspose.email as ae
contact = ae.mapi.MapiContact()
contact.name_info = ae.mapi.MapiContactNamePropertySet("Bertha", "A.", "Buell")
options = ae.personalinfo.vcard.VCardSaveOptions()
options.preferred_text_encoding = "utf-8"
contact.save("contact.vcf", options)
확장 속성을 포함한 VCard 파일 저장
표준 vCard 필드 외에도 확장 속성을 포함하여 vCard 파일을 강화할 수 있습니다. 이는 표준 vCard 사양에 포함되지 않은 추가 속성으로, 맞춤 설정을 확장합니다. 이를 활성화하려면 클래스의 use_extensions 속성을 설정하십시오 VCardSaveOptions 클래스를 True로 설정합니다. 이는 사용자 정의 또는 애플리케이션 전용 메타데이터를 추가할 때 특히 유용합니다. 다음은 확장 속성을 활성화한 vCard 파일을 저장하는 방법입니다:
import aspose.email as ae
contact = ae.mapi.MapiContact()
contact.name_info = ae.mapi.MapiContactNamePropertySet("Bertha", "A.", "Buell")
options = ae.personalinfo.vcard.VCardSaveOptions()
options.use_extensions = True
contact.save("contact.vcf", options)
VCard 형식에서 다중 연락처 읽기
VCard에서 모든 연락처를 가져오려면 다음을 사용할 수 있습니다 메서드:
- is_multi_contacts 메서드는 스트림에 다중 연락처가 있는지 판단합니다.
- load_as_multiple(file_path) 메서드는 VCard 파일에서 모든 연락처 리스트를 로드합니다.
- load_as_multiple(stream) 메서드는 VCard 스트림에서 모든 연락처 리스트를 로드합니다.
아래 코드 조각은 VCard 파일에서 여러 연락처를 읽는 과정을 보여줍니다:
import aspose.email as ae
contact = ae.mapi.MapiContact()
contact.name_info = ae.mapi.MapiContactNamePropertySet("Bertha", "A.", "Buell")
options = ae.personalinfo.vcard.VCardSaveOptions()
options.use_extensions = True
contact.save("contact.vcf", options)
if ae.personalinfo.vcard.VCardContact.is_multi_contacts("contact.vcf"):
ae.personalinfo.vcard.VCardContact.load_as_multiple("contact.vcf")
연락처 정보를 MHTML로 렌더링
Aspose.Email API를 사용하여 Outlook Contact를 MHTML로 변환할 수 있습니다. 다음 코드 예제는 MSG 파일에서 원래 가져온 자세한 연락처 정보를 포함하는 MHTML 파일을 생성하는 방법을 보여줍니다:
- MSG 파일을 다음과 같이 로드합니다 MapiMessage 객체.
- 메시지를 EML 형식으로 변환합니다.
- MHT 저장 옵션을 준비합니다:
- 본문 내용 인코딩을 활성화하고 원래 경계를 보존합니다.
- 헤더를 쓰고 vCard 정보를 렌더링하도록 MHT 형식 옵션을 설정합니다.
- MHT에 렌더링할 필드를 정의합니다.
- EML을 MHTML 파일로 저장합니다.