4

I am struggling to find a simple way to reply to an email in an Inbox using TestComplete.

At the moment I am using code for that can be found here http://support.smartbear.com/viewarticle/9022/ under the JScript section.

I have managed to create and send an email based off the body and subject to simulate a reply. However this is not sufficient as the software I am testing needs to have a real reply to link it to the message that has been previously sent to place it in the correct users mailbox.

Any help would be greatly appreciated. If you need more info please ask.

2 Answers2

0

I have found the answer. I was being rather silly in the fact that I thought that the MailItem.Reply() Method would send the email. However I have discovered that it must be explicitly sent with a MailItem.Send().

Here's my code:

//Creates a reply MailItem
var replyEmail = currentEmail.Reply();
//Creates a variable on the reply email's body
var body = replyEmail.Body; 
//Additional text to add
var additionaltext = "Reply to Email Message.\n"; 
//Start position for insert
var startpos = 0; 
//Inserts additional text to the beginning of the message
var fullBody = aqString["Insert"](body, additionaltext, startpos);
//Applies the new body to the reply email
replyEmail.Body = fullBody;
//Sends the new reply
replyEmail.Send();

The reason for having the new body is because otherwise a blank response is sent.

0

You should be able to do this without problems working with Outlook via COM. I have modified the sample in the article you mentioned to demonstrate how you can do this.

function Test()
{
  Log.Message(replyToMessage2010("account name", "sender email", "Test 1234321", "This is a reply"));
}

function replyToMessage2010(accountName, senderEMail, eMailSubject, replyText)
{
  var OutlookApplication = Sys.OleObject("Outlook.Application"); 
  var NamespaceMAPI = OutlookApplication.GetNamespace("MAPI"); 

  // Check whether the specified account exists:
  if (NamespaceMAPI.Accounts.Item(accountName) != null)
  {
    NamespaceMAPI.SendAndReceive(false);

    // Get the "Inbox" folder
    var inbox = NamespaceMAPI.Folders(accountName).Folders("Inbox");
    var items = inbox.Items;
    for (var i = 1; i < items.Count + 1; i++)
    {
      if (items.Item(i).Subject == eMailSubject && 
        items.Item(i).SenderEmailAddress == senderEMail && items.Item(i).UnRead)
      {
        var reply = items.Item(i).ReplyAll();
        reply.Body = replyText + reply.Body;
        reply.Send(); 
        return true;
      }   
    }
    return false;
  } else
  {
    OutlookApplication.Quit();
    return false;
  }
}
Dmitry Nikolaev
  • 3,803
  • 2
  • 19
  • 23