DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Automated Bug Fixing: From Templates to AI Agents
  • Dynamic File Upload Component in Salesforce LWC
  • Safeguarding Web Applications With Cloud Service Providers: Anti-CSRF Tokenization Best Practices
  • Make Your Backstage Templates Resilient

Trending

  • A Modern Stack for Building Scalable Systems
  • From Fragmentation to Focus: A Data-First, Team-First Framework for Platform-Driven Organizations
  • Key Considerations in Cross-Model Migration
  • Unlocking the Potential of Apache Iceberg: A Comprehensive Analysis

Read Outlook Email Template (.OFT) File & Save Message as MSG Format

By 
Sheraz Khan user avatar
Sheraz Khan
·
Jul. 18, 13 · Code Snippet
Likes (0)
Comment
Save
Tweet
Share
5.4K Views

Join the DZone community and get the full member experience.

Join For Free
This technical tip explains how to read outlook email template File (.OFT). Outlook templates are very useful when you want to send a similar email message again and again. Instead of preparing the message from scratch each time, first prepare the message in Outlook and save it as an Outlook template (OFT). After that, whenever you need to send the message, you can create it from the template, saving time writing the same text in the body or the subject line, setting formatting and so on. Aspose.Email’s MailMessage class can be used to load and read an Outlook template (OFT) file. Once the Outlook template is loaded in an instance of the MailMessage class, you can update the sender, recipient, body, subject and other properties.
//[C#]

// Load the Outlook template (OFT) file in MailMessage's instance
MailMessage message = MailMessage.Load("invitation to meeting.oft", MessageFormat.Msg);

// Set the sender and recipients information
string senderDisplayName = "John";
string senderEmailAddress = "john@abc.com";
string recipientDisplayName = "William";
string recipientEmailAddress = "william@xzy.com";

message.Sender = new MailAddress(senderEmailAddress, senderDisplayName);
message.To.Add(new MailAddress(recipientEmailAddress, recipientDisplayName));
message.HtmlBody = message.HtmlBody.Replace("DisplayName", "" + recipientDisplayName + "");

// Set the name, location and time in email body
string meetingLocation = "" + "Hall 1, Convention Center, New York, USA" + "";
string meetingTime = "" + "Monday, June 28, 2010" + "";
message.HtmlBody = message.HtmlBody.Replace("MeetingPlace", meetingLocation);
message.HtmlBody = message.HtmlBody.Replace("MeetingTime", meetingTime);

// Send the email or save as MSG and open in Outlook for further editing
SmtpClient client = new SmtpClient("host", 25, "username", "password");
client.Send(message);

// Save the message in MSG format and open in Office Outlook
MapiMessage msg = MapiMessage.FromMailMessage(message);
msg.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT);
msg.Save("Invitation.msg");
Process.Start("Invitation.msg");
 
//[VB.NET]

' Load the Outlook template (OFT) file in MailMessage's instance
Dim message As MailMessage = MailMessage.Load("invitation to meeting.oft", MessageFormat.Msg)

' Set the sender and recipients information
Dim senderDisplayName As String = "John"
Dim senderEmailAddress As String = "john@abc.com"
Dim recipientDisplayName As String = "William"
Dim recipientEmailAddress As String = "william@xzy.com"

message.Sender = New MailAddress(senderEmailAddress, senderDisplayName)
message.To.Add(New MailAddress(recipientEmailAddress, recipientDisplayName))
message.HtmlBody = message.HtmlBody.Replace("DisplayName", "" & recipientDisplayName & "")

' Set the name, location and time in email body
Dim meetingLocation As String = "" & "Hall 1, Convention Center, New York, USA" & ""
Dim meetingTime As String = "" & "Monday, June 28, 2010" & ""
message.HtmlBody = message.HtmlBody.Replace("MeetingPlace", meetingLocation)
message.HtmlBody = message.HtmlBody.Replace("MeetingTime", meetingTime)

' Send the email or save as MSG and open in Outlook for further editing
Dim client As SmtpClient = New SmtpClient("host", 25, "username", "password")
client.Send(message)

' Save the message in MSG format and open in Office Outlook
Dim msg As MapiMessage = MapiMessage.FromMailMessage(message)
msg.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT)
msg.Save("Invitation.msg")
Process.Start("Invitation.msg")
 
Template

Opinions expressed by DZone contributors are their own.

Related

  • Automated Bug Fixing: From Templates to AI Agents
  • Dynamic File Upload Component in Salesforce LWC
  • Safeguarding Web Applications With Cloud Service Providers: Anti-CSRF Tokenization Best Practices
  • Make Your Backstage Templates Resilient

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!