Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

One of the applications that I have to do an enhancement to soon has a number of emails that are sent from the application. To the point of verification, I need to see the delivery failure notifications. I've done some preliminary searching on how to do this, but, haven't managed to find anything that I could consider useful. The email client that would be used would be Outlook 2007 or 2010 on an exchange server.

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

Finally figured it out, with the exception of reportitems such as Undeliverables. Most of the current code is from snippets that I put together to make it work.

public void readOutlookTest()
        {
            Microsoft.Office.Interop.Outlook.Application app = null;
            Microsoft.Office.Interop.Outlook._NameSpace ns = null;
            Microsoft.Office.Interop.Outlook.MailItem item = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder subFolder = null;
            Microsoft.Office.Interop.Outlook.Application application = new Microsoft.Office.Interop.Outlook.Application();
            app = application;
            ns = application.Session;

            try
            {
                ns.Logon(null, null, false, false);
                inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
                subFolder = inboxFolder.Folders["folder name that you want to look in"];
                Console.WriteLine("Folder Name: {0}, EntryId: {1}", subFolder.Name, subFolder.EntryID);
                Console.WriteLine("Num Items: {0}", subFolder.Items.Count.ToString());
                for (int i = 1; i <= subFolder.Items.Count; i++)
                {
                        if (subFolder.Items[i] is ReportItem)
                        {
                            try
                            {
                                Console.WriteLine("Item: {0} is a Report Item.  I don't know how to deal with this yet.", i.ToString());
                            }
                            catch
                            {
                                Console.WriteLine("problems");
                            }
                        }
                        else if (subFolder.Items[i] is MailItem)
                        {
                            item = (MailItem)subFolder.Items[i];
                            item = subFolder.Items[i];
                            Console.WriteLine("Item: {0}", i.ToString());
                            Assert.IsTrue(item.SenderName == "display name of sender");
                            Assert.IsTrue(item.Subject.Contains("test"));
                            Assert.IsTrue(item.Body.Contains("text you need to look for"));
                        }
                        else
                        {
                            Console.WriteLine("item " + i + " is not a mail or report item.  have no use for it");
                        }
                    }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                ns = null;
                app = null;
                inboxFolder = null;
            }
        }
share|improve this answer
    
Can we use the same code using Java? I am badly stuck. Please help I need to check in outlook if mail is received or not and then parse and click on the provided link to accept or reject the request. Please help –  user2341727 May 21 '13 at 9:55
    
@user2341727 My experience has been that reading/writing to Exchange using c# is exactly 4100 times faster than using Java. I'm a Java stack guy through and through, but when you need to talk to Exchange, using c# just "works". You could always write a small c# app or service and call that with your java code, though. –  corsiKa May 22 '13 at 15:22
add comment

I think this is related to this question which suggests a SMTP pretend server:

Testing email generation

but I suspect this would need to be extended to 'know' about certain emails and be able to respond to doesnt@exist.com in the correct way.

share|improve this answer
    
That's correct. I would need to be able to read the message in the inbox. –  Lyndon Vrooman Jul 8 '11 at 12:47
add comment

You could use a test email account and access it using an IMAP/POP client?

What I do in my Django apps is I set the email backend to a file based one for testing. Emails are then not sent to the addresses but are stored in individual log files. I can then test the content of these files.

There are two similar but different scenarios here. One is testing email delivery (this is dependent on your provider) and the other is testing the content of email being sent from your application.

share|improve this answer
    
Yet to be able to get non-outlook clients to work. As for the log file, it is a great idea, however, our business sponsors also need to be able to see it work. Currently, for any email addresses that it has rules to always send with, we're using the same local, but different domain. It is a really good idea though. –  Lyndon Vrooman Jul 8 '11 at 21:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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