Outlook 연락처 작업
연락처 생성, 저장 및 읽기
MapiMessage와 마찬가지로 Aspose.Email은 Outlook 연락처를 생성할 수 있게 합니다. MapiContact 클래스는 Outlook 연락처를 만들기 위해 필요한 모든 연락처 관련 속성을 제공합니다. 이 문서는 MapiContact 클래스를 사용하여 Outlook 연락처를 생성, 저장 및 읽는 방법을 보여줍니다.
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)
버전 3 VCF 형식으로 연락처 저장
VCF 형식 버전 3으로 연락처를 저장하려면, VCardSaveOptions 클래스. VCardSaveOptions 클래스의 새 인스턴스를 생성하고, VCardSaveOptions 객체의 version 속성을 VCardVersion.V30으로 설정합니다. 이는 vCard 버전을 3.0으로 지정합니다. 그런 다음 MapiContact 객체의 save 메서드를 호출하고 파일 이름 "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)
MapiContact 읽기
MapiContact 클래스는 Outlook MSG와 VCard 형식의 연락처를 모두 로드하는 데 사용할 수 있습니다. 다음 코드 스니펫은 MSG 및 VCF로 저장된 Outlook 연락처를 MapiContact에 로드하는 방법을 보여줍니다.
MSG에서 연락처 로드
다음 코드 스니펫은 MSG에서 연락처를 로드하는 방법을 보여줍니다.
VCard에서 연락처 로드
다음 코드 스니펫은 vCard에서 연락처를 로드하는 방법을 보여줍니다.
지정된 인코딩으로 VCard에서 연락처 로드
다음 코드 스니펫은 지정된 인코딩으로 vCard에서 연락처를 로드하는 방법을 보여줍니다.
지정된 인코딩으로 VCard 연락처 항목 저장
vCard 파일을 저장할 때 비 ASCII 문자와의 호환성을 보장하기 위해 문자 인코딩을 지정할 수 있습니다. VCardSaveOptions 객체의 preferred_text_encoding 속성을 "utf-8"로 설정합니다. 다음 코드 스니펫은 이 기능을 프로젝트에 구현하는 방법을 보여줍니다.
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 사양에 정의된 필드 외에 추가 속성이나 특성인 확장 필드 사용을 포함한 옵션을 지정할 수 있습니다. use_extensions 속성은 VCardSaveOptions 클래스가 이를 수행하도록 합니다. 다음 코드 스니펫은 확장 필드를 포함한 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에서 모든 연락처 목록을 가져오려면 다음 메서드가 필요합니다:
# Checks whether VCard source stream contains multiple contacts.
aspose.email.personalinfo.vcard.VCardContact.is_multi_contacts(stream)
# Loads list of all contacts from VCard file.
aspose.email.personalinfo.vcard.VCardContact.load_as_multiple(file_path, encoding)
# Loads list of all contacts from VCard stream.
aspose.email.personalinfo.vcard.VCardContact.load_as_multiple(stream, encoding)
아래 코드 스니펫은 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로 렌더링
Outlook 연락처는 Aspose.Email API를 사용하여 MHTML로 변환할 수 있습니다. 이 예제는 VCard를 MapiContact에 로드한 후 MailMessage API를 사용해 MHTML로 변환하는 방법을 보여줍니다.