Read Outlook Email Template (.OFT) File & Save Message as MSG Format
Join the DZone community and get the full member experience.
Join For Free//[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")
Opinions expressed by DZone contributors are their own.
Comments