Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created September 26, 2025 15:42
Show Gist options
  • Save aspose-com-gists/d28b3be477280069d7de624967860c72 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/d28b3be477280069d7de624967860c72 to your computer and use it in GitHub Desktop.
Read, Create, and Edit Outlook Email Templates (OFT) in C#
var msg = MapiMessage.Load("input.msg");
msg.Save("template.oft", SaveOptions.DefaultOft);
FileFormatInfo info = FileFormatUtil.DetectFileFormat("input.msg");
if (info.FileFormatType == FileFormatType.Oft)
{
Console.WriteLine("This is an Outlook Template file.");
}
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);
var eml = MailMessage.Load("input.eml");
eml.Save("template_from_eml.oft", SaveOptions.DefaultOft);
var msg = MapiMessage.Load("input.msg");
if (msg.IsTemplate)
{
Console.WriteLine("The message is an Outlook Template.");
}
var saveOptions = new MsgSaveOptions(MailMessageSaveType.OutlookTemplateFormat);
msg.Save("template_alt1.oft", saveOptions);
saveOptions = SaveOptions.CreateSaveOptions(MailMessageSaveType.OutlookTemplateFormat);
msg.Save("template_alt2.oft", saveOptions);
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