Sunday, July 19, 2009

Verifying Email notifications

For long time, I was looking a solution to automate the verification of email contents. It required to verify for few user accounts, attachments like Excel, PowerPoint and PDF docs. We have few critical features, which required to verify email contents and attachments. Silktest does not have any built-in functions for this activity. However I have to find a solution. The solution should supports IE6 and IE7 browsers and Windows 2000, Windows XP and Vista OS. I had four choices in mind. They are,

  1. Using a command line utility
  2. Using MS Office Outlook COM interface
  3. Using Collaboration Data Objects (CDO) Interface with Outlook Express
  4. Worst case - Automate any email client with UI

Automate any email client with UI
This option was last one. Because I do not want to automate with User Interface. We can build the solution in couple of weeks effort. The issue is the changes with that client. I have to look on support for different Operating Systems such as Windows XP and Vista.

Using Collaboration Data Objects (CDO) with Outlook Express
In my first company, I have used CDO with Visual Basic. See my previous post - Checking Mail Notification. I got a surprise, while I was searching information for CDO Help. Microsoft has stopped the updates on Outlook Express. Earlier Internet Explorer Intallation was bundled with Outlook Express.

Using MS Office Outlook COM interface
I am familiar with VB script. I have used Outlook COM interface [CreateObject("Outlook.Application")] earlier. The issue is, the particular user account mailboxes should be opened, while executing VB Script. Also I thought the license and installation costs.

Using a command line utility
I have searched many times and found a utility. GetMail is a command line utility and it is working in all windows OS. It is available at GETMAIL for Windows It is a cheapest and best utility to fit for my requirements.

Different Cmdline switches of GetMail
Getmail has different switches for various purposes. You can opt appropriate switches as per your requirement.
 

GetMail v1.33: WinNT console utility to download a mailbox's mail.
syntax:
Getmail -u <user> -pw <password> -s <server> [optional switches (see below)]
Getmail -install [ see install details below ]
Getmail -profile [-delete | "<default>"] [profile1] [profileN] [-q]
Getmail -h [-q]
Getmail -forceextract filename

-install <server> <userid> <password> [<delete> [<xtract> [<try> [<port> [<profile>]]]]]
: set's POP3 server, login, password, whether to delete or not (Yes/No),
whether to automatically extract base64/7bit/UU encoded files or not (Yes/No),
number of tries and port for profile
(<delete> <xtract> <try> and <port> may be replaced by '-').

-u <userid> : Specify userid on remote pop3 host
-pw <password>: Specify password for userid on remote mail host
-s <server> : Specify mail server (pop3) to contact
-nodelete : Do not delete messages after downloading (default)
-delete : Delete messages after downloading
-noxtract : Do not extract base64/7bit/UU files after downloading (default)
-xtract [defname]: Extract base64/7bit/UU encoded files after downloading messages
defname is an optional default filename for the extracted file
-domainstamp : Prepend sender's domain name to extracted attachments
-headersonly : Download only the headers of the message
-port <port> : port to be used on the server, defaults to POP3 (110)
-p <profile> : send with SMTP server, user and port defined in <profile>.
-q : supresses *all* output.
-n <n> : Only get 'n' messages
-m <n> : Only get message # n
-b <n> : Retrieve messages beginning from # n
-plain : Extract text/plain segments too (usually ignored)
-h : displays this help.
-try <n times>: how many attempts to access mail. from '1' to 'INFINITE'
-ti <n> : Set timeout to 'n' seconds.
-forceextract fn: Attempt to extract any encoded messages in 'fn'

Installing GetMail
You need to follow the belows steps to install it. Assume that getmail.exe is stored under D:\tools.
  1. First open a command prompt.
  2. Go to D:\tools folder.
  3. Install it by executing below commmand
    Getmail -install mailserver script1@auto.com wrongpwd
    Here mailserver means the mail Server name or IP address

Verifying GetMail
To verify the GetMail installation, you can use following steps.
  1. Goto folder D:\tools
  2. Execute the following command for any user.
    For example, D:\tools\getmail.exe -u script1 -pw TestPassword -s mailserver
  3. Check any error exists on command prompt.
  4. Check on that folder, whether all the mails are downloaded or not. You can see mails like msg1.txt,msg2.txt,..etc

4Test code - To Verify the GetMail
 

[ ] sMailCommand = "{gsToolsDir}\getmail.exe -u {sUser} -pw {sPass} -s {sServer} {sAdditionalSwitch}"
[ ] Print ("Mail Command: {sMailCommand}")
[+] // if (bDeleteAfterReceive)
[ ] // sMailCommand = "{gsToolsDir}getmail.exe -u {sUser} -pw {sPass} -s {sServer} -delete"
[+] // else
[ ] // sMailCommand = "{gsToolsDir}getmail.exe -u {sUser} -pw {sPass} -s {sServer} -nodelete"
[ ] // Checking any errors on command line output
[+] if( 0 != SYS_Execute( sMailCommand, lsGetmailOut ) )
[ ] ListPrint( lsGetmailOut )
[ ] LogError ( "FAIL. Unable to receive the mail." )
[ ] return FALSE
[ ]

2 comments:

Alex said...

I often work with emails and once something must have happened with some of them. In 2 hours I understood that they were damaged. Fortunately a friend called me up and advised - oe extract. I was marveled,because the program decided my issue quite easy and free of charge as far as I remember.

James Inderson said...

So impressive blog. I really appreciate your info. Thanks for sharing.

desktop notification software