I want to know how to use outlook to test mails (the mail has a link that needs to be clicked to approve or deny the request). How do I write this in Selenium Webdriver in c#. I am quite new to selenium. I would like to learn how to auomate the testing in C#. Please do share your knowledge with me.

Something related to this thread. Is mail testing with selenium possible?

  • Welcome to SQA Stack Exchange Yvette. Would you like to test in the web version of outlook, or the desktop application. Sep 18, 2012 at 14:37
  • 1
    why do you think you need Outlook to test the mails ? What exactly are you trying to test - that the content of a mail is a valid link ? Sep 18, 2012 at 15:13
  • Please proof read your question for basic typing errors before posting to make it readable for others increasing people's interest to post an answer. Something like "ro" for "to" can easily be corrected. Sep 19, 2012 at 21:57

3 Answers 3


You have a few options. You could automate Outlook like Lyndon has linked to in his answer, or you could use a web email account instead and use a tool like Selenium to automate it, or probably the most efficient and simple way would be to use an SMTP library that can receive e-mails and programatically parse the responses and open the link in a browser.

EDIT: I meant IMAP library (to receive an email). SMTP is used for sending mail. Here's some documentation on using IMAP to access e-mail from a gmail account: https://developers.google.com/google-apps/gmail/xoauth2_libraries

  • +1 on the SMTP library. I would not recommend involving any third party tool if you can help it and that includes any kind of email client. If all you need to do is click a link, take the shortest path possible. Otherwise the minute your webmail client is updated, you will have to update your tests to compensate.
    – Trish Khoo
    Sep 24, 2012 at 14:28

When people think about test automation, far too often, they think of Selenium and the like. Libraries like Selenium, Webdriver, WATiR, however, will only help in a browser.

If you want to do this in Outlook, and with C#, you will not need those libraries. You may instead want to look to use Microsoft.Office.Interop.Outlook.

I had a similar problem a while ago, with the answer here. That might get you onto a good start.

  • Hi Lyndon, i read your post. Do you mind helping me on how to incorporate the code[your outlook code mentioned on the link] into my code.
    – Yvette
    Sep 18, 2012 at 15:49
  • Definitely go with C# or other .NET tools with Outlook. In my experience with SilkTest and Outlook, Outlook does not play well at all with third-party automation tools. Sep 18, 2012 at 16:52

Why don't you use c# code itself ?

 Outlook.Application oApp = new Outlook.Application();
                Outlook.NameSpace olNameSpace = oApp.GetNamespace("mapi");
                Outlook.MAPIFolder oInbox  = olNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                Outlook.Items oItems  = oInbox.Items;
                Console.WriteLine("Total : " + oItems.Count);
                oItems = oItems.Restrict("[Unread] = true");
                Console.WriteLine("Total Unread : " + oItems.Count); //Unread Items
                Outlook.MailItem oMsg;

                for (int i = 0; i < oItems.Count; i++)
                    oMsg = (Outlook.MailItem)oItems.GetFirst();


                    IE browser1 = new IE(oMsg.Links);


Not the answer you're looking for? Browse other questions tagged or ask your own question.