Created
September 26, 2025 15:42
-
-
Save aspose-com-gists/d28b3be477280069d7de624967860c72 to your computer and use it in GitHub Desktop.
Read, Create, and Edit Outlook Email Templates (OFT) in C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var msg = MapiMessage.Load("input.msg"); | |
msg.Save("template.oft", SaveOptions.DefaultOft); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FileFormatInfo info = FileFormatUtil.DetectFileFormat("input.msg"); | |
if (info.FileFormatType == FileFormatType.Oft) | |
{ | |
Console.WriteLine("This is an Outlook Template file."); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var template = MapiMessage.Load("template.oft"); | |
template.Subject = "Updated Subject Line"; | |
template.Body = "This is an updated body text."; | |
template.Recipients.Add("[email protected]"); | |
template.Save("updated_template.oft", SaveOptions.DefaultOft); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var eml = MailMessage.Load("input.eml"); | |
eml.Save("template_from_eml.oft", SaveOptions.DefaultOft); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var msg = MapiMessage.Load("input.msg"); | |
if (msg.IsTemplate) | |
{ | |
Console.WriteLine("The message is an Outlook Template."); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var saveOptions = new MsgSaveOptions(MailMessageSaveType.OutlookTemplateFormat); | |
msg.Save("template_alt1.oft", saveOptions); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
saveOptions = SaveOptions.CreateSaveOptions(MailMessageSaveType.OutlookTemplateFormat); | |
msg.Save("template_alt2.oft", saveOptions); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var saveOptions = new MsgSaveOptions(MailMessageSaveType.OutlookTemplateFormat); | |
eml.Save("template_alt1.oft", saveOptions); | |
saveOptions = SaveOptions.CreateSaveOptions(MailMessageSaveType.OutlookTemplateFormat); | |
eml.Save("template_alt2.oft", saveOptions); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment