2012-10-23 55 views
4

我很努力地找到一種使用TestComplete在收件箱中回覆電子郵件的簡單方法。使用TestComplete回覆電子郵件

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

我已經成功地創建併發送了一封基於身體的郵件,並且可以模擬回覆。然而,這並不足夠,因爲我正在測試的軟件需要有一個真正的回覆,將它與先前發送的郵件關聯起來,以將其放置在正確的用戶郵箱中。

任何幫助將不勝感激。如果您需要更多信息,請詢問。

回答

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

之所以具有新的身體,否則空響應發送。