Saturday, March 21, 2015

Send mail using Outlook and .oft templates

There is already a page for sending mail using Outlook library.
Now this small code is a small tweak i.e. using Outlook Template (*.oft) file.

If you see the code there is hardly any complication but this exercise is time consuming as a whole.
It is because defining the different mail templates takes a lot of time from business POV.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace emailTemplateTest {
 class Program {
  static void Main(string[] args) {
   try {
    Outlook.Application otApp = new Outlook.Application(); // create outlook object
    Outlook.NameSpace ns = otApp.Session;
    Outlook.Folder folder = otApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDrafts) as Outlook.Folder;
    Outlook.MailItem otMsg = otApp.CreateItemFromTemplate(@ "d:\a2.oft", folder) as Outlook.MailItem; // Open the mail template
    Outlook.Inspector oInspector = otMsg.GetInspector;
    Outlook.Recipient otRecip = (Outlook.Recipient) otMsg.Recipients.Add("Temp@hotmail.com");
    if (otRecip.Resolve()) // validate recipient address
    {
     // Modify the body text as required
     otMsg.Send(); // Send Mail
     otRecip = null;
     otMsg = null;
     otApp.Quit();
    }
   } catch (Exception e) {
    Console.WriteLine("{0} Exception caught: ", e);
   }
  }
 }
}

15 comments:

  1. Raipur girls welcoming you to making you relax and happy by their top class physical services, and at the same time the independent Raipur Escorts are available at you reasonable price.
    http://www.raipurescort.com

    Raipur Escorts

    Raipur Escort

    Raipur Escorts service

    Raipur Escorts Agency

    Independent Raipur Escorts

    Independent Raipur Escort

    Raipur Escorts Girl

    Escorts in Raipur

    Escorts Service in Raipur

    ReplyDelete
  2. Welcome to High Class Surat Escorts Service, the luxurious Surat Escort Services where you can find the most beautiful Escort Sexy and Hot Call girls in Surat and Other Citys Best Escort Services in India.

    Surat Call Girl, Surat Escorts Service

    Surat Call Girls, Surat Escorts

    Call Girls in Surat, Surat Escort

    Surat Escorts, Call Girl in Surat

    Surat Escorts, Surat Escort Service

    ReplyDelete
  3. Mumbai Escorts sillky.in Do not be shy, tell your wish to me, experience-your objectives and should be to the really ecstasy that's me, the usually, the one, for you in here I will be a little, table beauty with awesome perspective, prolonged black smooth locks and interest that is hypnotic.
    Mumbai Escorts, Independent Mumbai Escorts http://sillky.in
    Mumbai Escorts Service, Mumbai Escort http://www.dimpy.in
    Mumbai Call Girl, Call Girls in Mumbai http://www.mumbaicallgirlservice.com
    Call Girl in Mumbai, Mumbai Call Girls http://www.callgirlservicemumbai.com
    Mumbai Escorts, Mumbai Call Girl Service http://www.callgirlinmumbaiescorts.com
    Mumbai Escorts, Mumbai Call Girls http://www.mumbaiescortss.biz
    Call Girl in Mumbai, Call Girls Service in Mumbai http://www.mumbaiescortscallgirl.com
    Mumbai Escorts, Call Girls in Mumbai http://www.meghnakaur.com

    ReplyDelete
  4. Welcome to High Class Surat Escorts Service, the luxurious Surat Escort Services where you can find the most beautiful Escort Sexy and Hot Call girls in Surat and Other Citys Best Escort Services in India.

    Visit The Site For More Details -: http://www.anuroy.com/

    Chennai Escorts, Chennai Call Girls

    Chennai Call Girl, Chennai Escorts Service

    Call Girls Chennai, Chennai Escort

    Chennai Escorts, Chennai Escorts Service

    Call Girls in Chennai, Chennai Escort

    ReplyDelete