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

21 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
  11. Hi Everyone My Self Urvasi From Gurgaon 24x7 Girls Service Escorts provider We Providing Indian Russian Model Call Girls service There Are desirable | Escorts in Gurgoan | Gurgoan Escorts | Escorts Service in Gurgoan| Gurgoan Escorts Service

    ReplyDelete
  12. It is the momentary pleasure that makes life special, makes life very desirable to you. For a moment’s pleasure, you can forget weeks of worries. Their lies the specialty of life. When feels just tied up with the tensions of life you must get a respite from it with some interesting ways. An interesting dating with a loving woman can bring out of the tensions of life. There lies the specialty of the Riyaroyal who are skilled enough to bring you out of sufferings of life and present you the joys of life. They are known for their amazing skills and thus have clients from all over the world. Not only the travelers but the locals are also absolutely fond of these amazing ladies.
    Riyaroyal is avialble 24/7 for you. Click here if you want to book.

    ReplyDelete
  13. Our wonderful Escort assistance in Native Indian contains first-class excellent the best great high quality of as well as mature females. We provide then real pictures of our females Escorts on our website to the customers can use. All of our Escorts are extremely certified and well were. Our Escorts come from a well-known background and withstand an elegant way of life when they are not at work. Escorts in JLT is provided Rajurani with beautifull and clean girls.0.

    ReplyDelete
  14. Hi, Our Indian Angels main policy is the customer satisfaction and we have no extra charges like that go to outside to the clients or regarding venue. And we are very clear that we show in site is the same girl provide you not like on site is that is differ is actuality. This quality make differ to others which are belongs to this fields. We provide service to the customers 24/7. Click here if you want to know more.

    ReplyDelete
  15. The escorts in Bangalore are actually well known for as long as their customers with some of the the majority acceptable body massages. Roughly everyone would have a preference to be serve
    Independent Escorts Bangalore | Escorts Bangalore | Bangalore Escorts | Female Escorts Bangalore

    ReplyDelete