המרה ועיבוד של תבניות 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)