Wednesday, May 16, 2012

Send mail using Microsoft Outlook

Already posted how to mail using SMTP; but now in this implemenation will show how to send mail using Microsoft Outlook object.
But there a basic rule of these implementation:
  1. Create the required objects.
  2. Add recepient, main subject, mail body, attachment.
  3. Send mail and validate.
  4. Release resources.
using Outlook = Microsoft.Office.Interop.Outlook;

public void SendTestMail()
        Outlook.Application otApp = new Outlook.Application();// create outlook object
        Outlook.NameSpace ns = otApp.Session;
        Outlook.MailItem otMsg = (Outlook.MailItem)otApp.CreateItem(Outlook.OlItemType.olMailItem); // Create mail object
        Outlook.Inspector oInspector = otMsg.GetInspector;
        Outlook.Recipient otRecip = (Outlook.Recipient)otMsg.Recipients.Add("");
        otRecip.Resolve();// validate recipient address
        otMsg.Subject = "test subject";
        otMsg.Body = "text message";
        String sSource = "C:\\Test.txt";
        String sDisplayName = "TestAttachment";
        int iPos = (int)otMsg.Body.Length + 1;
        int iAttType = (int)Outlook.OlAttachmentType.olByValue;  
        Outlook.Attachment oAttach = otMsg.Attachments.Add(sSource,iAttType,iPos,sDisplayName); // add attachment
        otMsg.Send(); // Send Mail
        otRecip = null;
        otAttach = null;
        otMsg = null;
        otApp = null;
    catch (Exception e)
        Console.WriteLine("{0} Exception caught: ", e);
    return 0;


  1. Hi Kuntal Saha,
    Same coding is working fine in my system. But when i published in IIS it is not working :(. Could you please help me in this.

    1. Hi Raj,
      I would rather suggest you creating a service seperately to handle mail communication. Consume the service whenever you wanna send mail.


  2. just tried this code, doesnt do anything for me :(

  3. Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. microsoft powerpoint courses malaysia

    1. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts.
      Cyber Security Projects for Final Year

      JavaScript Training in Chennai

      Project Centers in Chennai

      JavaScript Training in Chennai

  4. It is because some antivirus programs often consider auto-emails that are trying to be sent or downloaded as phishing, spam, or virus carriers and thus block them. microsoft support number

  5. Get solution for all error of Hotmail in one place by clicking on login we are third-part hotmail support provider on nominal cost. We have expert to fix your error on call quickly.
    Our services also for outlook, Microsoft has upgraded it’s email services from hotmail to outlook so those are using upgraded version of Microsoft and having any issues they can dial our too-free number 1-844-797-8692 or click login and fill a callback form.

  6. Hi my friend! I want to say that this post is awesome, great written and include almost all important infos. I would like to see more posts like this. Special info: The Ninja Guide To How To Password Protect Folder Better.

  7. All you have to do is key in your questions and multiple possible solutions will be thrown up by Microsoft Help. Microsoft Help also provides inbuilt trainings that walk you through various packages.reset windows 10 password

  8. Sebetulnya banyak penjelasan mengenai tentang cara menggugurkan kehamilan . Namun , belum tentu semua ulasan yang beredar di media internet tentang cara ampuh menggugurkan kandungan benar-benar terbukti manjur dalam mengatasi persoalan anda . Kenapa bisa begitu ? Memang banyak sekali kita jumpai topik-topik yang berbeda di berbagai situs dalam membahas content ini , ada cara alami dan medis . Cara tradisional belum jelas tentang kebenarannya . Oleh sebab itu , sebaiknya gunakan obat menggugurkan kandungan yang sudah jelas terbukti melalui riset . Apa saja ciri ciri pubertas pada perempuan yang terjadi pada wanita ? . Ternyata gejala menopause dialami oleh wanita yang berusia 45 sampai 55 tahun – usia rata-rata yang diketahui saat ini adalah 55 tahun . Dan satu hal lagi perempuan sangat penting untuk merawat daerah kewanitaannya , cara menjaga daerah kewanitaan agar tetap rapat harus dimulai sejak dini

  9. These are some great tools that i definitely use for SEO work. This is a great list to use in the future..

  10. Hi friends! I'm Roma Sehgal. I live in New Mumbai. I like enjoying daily with different people. If you are in New Mumbai and want to spend some time with me in loneliness, you can call me at any time. I will reach you within hours in any hotel in Mumbai. Most people like my escorts service. No hesitation. Go to my official website for more information.

    call girl in the orchid hotel mumbai
    call girl in the lalit hotel mumbai
    call girl in the oberoi hotel mumbai
    call girl in grand hyatt hotel mumbai
    call girl in sahara star hotel mumbai
    call girl in the taj mahal palace hotel mumbai

    call girl in four seasons hotel mumbai
    call girl in trident hotel bandra Kurla mumbai
    call girl in sofitel hotel mumbai

  11. Hire sexy Call girls in Guwahati or Escorts in Guwahati for incall or outcall Escort services in Guwahati hotels from Diya roy #No.1 premier escort agency. We have 1500+ Guwahati call girls profiles and independent Guwahati call girls for providing 24x7 escort services.