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);
            }
        }
    }
}

11 comments:

  1. I love fashion and prompting over get that is tough-minded. i have an shirty search concerning Invest separate vibrate occasionally side by side in somewhat passionate method and assembly blooming men. From transportation this out I possibly can could not isolate me. Escorts Service in Gurgaon

    ReplyDelete

  2. night life and much more. For men who like to be seen out on the town with wonderful models and to appreciate the best encounters that the urban community nightlife brings to the table, we have set up a strong notoriety of being the best Escorts Service in Gurgaon

    ReplyDelete
  3. Delhi Escorts is a rising agency who only enlists high class Delhi escort models to fulfil all the desires of the most refined clients, for business occasions or personal fun. Delhi Escorts

    ReplyDelete
  4. Once you are with me I will get you to Deep Ocean of erotic enjoyment that you always desire but never have felt before knew lots of position, which are very favorable in providing you complete pleasure.I have wide range of lingerie and hot dresses special for my valuable clients.
    Independent Bangalore Escorts

    ReplyDelete
  5. My Escort is Top and Exellent. I perform your hearty longing with filled of obsession, because all men necessities a content Happy.
    Female Escorts Bangalore

    ReplyDelete
  6. you are seeking ways to solve your personal concerns, the maybe you would think of having the Top nature of Enjoy. In this case, escorts of Mumbai may be Most helpful for you. 
    Mumbai Escorts Service

    ReplyDelete
  7. Mumbai escorts are Very Good in every and All field of Escort service. The beautiful and amazing Escorts girls in.
    Mumbai Escorts

    ReplyDelete
  8. These escort ladies or girls can aid convalesce mentally. People know that, these escort girls always give their best shot in order to fulfill their client’s requirement.
    Powai Escorts Service
    Andheri Escorts Service
    vashi Escorts Service
    Bandra Escorts Service

    ReplyDelete
  9. Most gorgeous Girls come and join this Business, for their pocket money, but as the Company is prospering in a big way, people are willing to take this as the livelihood. To be one of the VIP Escorts, you have to concentrate only on one thing, and that is the customers’ Enjoyment.
    Thane Escorts Service
    Juhu Escorts Service
    Chembur Escorts Service
    Andheri Escorts

    ReplyDelete
  10. My High-Quelity Escorts service is the most convenient and Very friendly service on the world, and no other escorts agency goes to the same level that we go to make sure great stages of Customer service.
    Vashi Escorts
    Thane Escorts
    Juhu Escorts
    Powai Escorts
    Mumbai Escorts

    ReplyDelete