使用TestComplete回复电子邮件

时间:2012-10-23 14:50:32

标签: testcomplete

我正在努力寻找一种使用TestComplete回复收件箱中的电子邮件的简单方法。

目前我使用的代码可以在JScript部分的http://support.smartbear.com/viewarticle/9022/找到。

我已设法创建并发送基于正文的电子邮件,并根据模拟回复。但是这还不够,因为我测试的软件需要有一个真实的回复才能将它链接到之前发送的消息,以便将其放入正确的用户邮箱。

非常感谢任何帮助。如果您需要更多信息,请询问。

2 个答案:

答案 0 :(得分:2)

您应该能够在没有通过COM使用Outlook的问题的情况下执行此操作。我已经修改了您提到的文章中的示例,以演示如何执行此操作。

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;
  }
}

答案 1 :(得分:0)

我找到了答案。我觉得MailItem.Reply()方法会发送电子邮件,这让我很傻。但是我发现必须使用MailItem.Send()显式发送它。

这是我的代码:

//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();

拥有新主体的原因是因为否则会发送空白响应。

相关问题