Outlook 템플릿(OFT) 변환 및 처리
**Outlook 템플릿(OFT)**은 반복적인 이메일 전송 과정을 간소화하는 편리한 방법을 제공합니다. 매번 처음부터 동일한 이메일을 작성하는 대신 Outlook에서 메시지를 만든 뒤 Outlook 템플릿(OFT)으로 저장할 수 있습니다. 이후 유사한 메시지를 보낼 때마다 템플릿에서 빠르게 생성할 수 있어, 메시지 본문의 동일한 내용, 제목, 서식 등을 다시 작성할 필요가 없습니다.
OFT 파일 로드, 수정 및 저장
Aspose.Email은 MailMessage 클래스는 Outlook 템플릿 파일(OFT)을 로드하고 조작합니다. Outlook 템플릿을 해당 클래스의 인스턴스로 로드하면 MailMessage 클래스를 사용하면 발신자, 수신자, 메시지 본문, 제목 및 다양한 속성을 쉽게 업데이트할 수 있습니다.
import aspose.email as ae
# Load the OFT file
oft_file_path = "your_template.oft"
mail_message = ae.MailMessage.load(oft_file_path)
# Update properties as needed
mail_message.subject = "Updated Subject"
mail_message.body = "Updated body text."
# Save the updated message as an MSG file
msg_file_path = "updated_message.msg"
mail_message.save(msg_file_path, ae.MailMessageSaveType.outlook_message_format_unicode)
print(f"Updated message saved to {msg_file_path}")
필요한 업데이트를 마친 후, 다음을 사용하여 이메일을 보낼 수 있습니다 SmtpClient 클래스:
import aspose.email as ae
mail_message = ae.MailMessage.load("updated_message.msg")
# Send the email
with ae.clients.smtp.SmtpClient("smtp.example.com", 587, "username", "password", ae.clients.SecurityOptions.AUTO) as client:
client.send(mail_message)
MSG 파일을 Outlook 템플릿으로 저장
이메일을 생성한 후 OFT 파일로 저장하려면 다음을 사용합니다 MailMessage 클래스. 다음 코드 샘플은 이메일을 Outlook 템플릿으로 저장하는 방법을 보여줍니다:
import aspose.email as ae
# Create a new MailMessage
message = ae.MailMessage()
message.subject = "Sample Outlook Template"
message.html_body = "<html><body>This is the body of the email.</body></html>"
message.from_address = ae.MailAddress("your.email@example.com", "Your Name")
# Save the MailMessage as an Outlook Template (OFT) file
oft_file_path = "sample_template.oft"
message.save(oft_file_path, ae.SaveOptions.default_oft)
print(f"Outlook Template saved as {oft_file_path}")
OFT 및 MSG 파일 유형 식별
다음 코드 스니펫은 로드된 MAPI 메시지가 표준 이메일 메시지인지 Outlook 템플릿(OFT)인지 판단하는 방법을 보여줍니다:
import aspose.email as ae
msg = ae.mapi.MapiMessage.load("message.msg")
is_oft = msg.is_template # returns False
msg = ae.mapi.MapiMessage.load("message.oft")
is_oft = msg.is_template # returns True
MSG 파일을 로드한 후, 코드는 is_template 속성을 확인합니다 MapiMessaage 클래스는 True 또는 False를 반환합니다. false를 반환하면 로드된 메시지는 표준 이메일 메시지이며 Outlook 템플릿이 아닙니다. 반대로 true를 반환하면 해당 메시지는 표준 이메일이 아니라 Outlook 템플릿입니다.
MapiMessage 또는 MailMessage를 OFT로 저장
다음은 SaveOptions 는 사용자가 저장할 때 추가 옵션을 지정할 수 있게 하는 추상 기본 클래스입니다 MailMessage 특정 형식으로 변환합니다. 다음 코드 샘플은 메시지를 OFT 형식으로 저장하는 방법을 보여줍니다:
import aspose.email as ae
# Save the MailMessage to OFT format
eml = ae.MailMessage.load("message.eml")
eml.save("message.oft", ae.SaveOptions.default_oft)
# or alternative way 2
save_options = ae.MsgSaveOptions(ae.MailMessageSaveType.outlook_template_format)
eml.save("message.oft", save_options)
# or alternative way 3
save_options = ae.SaveOptions.create_save_options(ae.MailMessageSaveType.outlook_template_format)
eml.save("message.oft", save_options)
# Save the MapiMessage to OFT format
msg = ae.mapi.MapiMessage.load("message.msg")
msg.save("message.oft", ae.SaveOptions.default_oft)
# or alternative way 2
save_options = ae.MsgSaveOptions(ae.MailMessageSaveType.outlook_template_format)
msg.save("message.oft", save_options)
# or alternative way 3
save_options = ae.SaveOptions.create_save_options(ae.MailMessageSaveType.outlook_template_format)
msg.save("message.oft", save_options)