我想在testcomplete中使用vb腳本語言發送Outlook郵件。我可以發送,但如果outlook在我的電腦中打開,那麼只有郵件將被髮送,並且如果在我的電腦中未打開郵件,我的郵件將不會被髮送,直到執行此腳本後仍然打開郵件。如何通過testcomplete在PC中打開outlook展望郵件outlook郵箱
這裏是我的代碼:
Function SendMail
Dim objOutLook, NamespaceMAPI,objNewMail, fso, SendReceiveControls
Dim strTo,strCc ,strBcc ,strSubject, AccountName,strAttachmentPath
strSubject="test"
[email protected]
[email protected]
strBcc [email protected]
strAttachmentPath="c:\text.txt"
If strTo ="" and strCc = "" and strBcc =""Then
Exit function
ElseIf strSubject =""Then
Exit function
End If
Set objOutLook = CreateObject("Outlook.Application")
Set NamespaceMAPI = objOutLook.GetNamespace("MAPI")
Set objNewMail = objOutLook.CreateItem(olMailItem)
objOutLook.DisplayAlerts =True
objNewMail.TO = strTo
objNewMail.CC = strCc
objNewMail.BCC=strBcc
objNewMail.Subject = strSubject
objNewMail.Body = strMsg
If strAttachmentPath <> "" Then
Set fso =CreateObject("Scripting.FileSystemObject")
If fso.FileExists(strAttachmentPath) Then
objNewMail.Attachments.Add(strAttachmentPath)
objNewMail.display
Else
msgbox "Attachment File Does not exists"
End If
End If
AccountName="[email protected]"
' Finding the "Send/Receive" control
Set SendReceiveControls = NamespaceMAPI.GetDefaultFolder("Inbox")._
CommandBars("STANDARD").Controls("Send/Receive")
Set Item = Nothing
'msgbox "send:"&SendReceiveControls.Controls.Count
For I = 1 To SendReceiveControls.Controls.Count
If InStr(SendReceiveControls.Controls(I).Caption, AccountName) > 0 Then
Set Item = SendReceiveControls.Controls(I)
'msgbox "send1"&SendReceiveControls.Controls(I)
Exit For
End If
Next
' Executing the "Send/Receive" action
Item.Controls(1).Execute()
objOutLook.Quit
''''''' Releasing objects '''''''
Set objOutLook =Nothing
Set objNewMail = Nothing
Set fso = Nothing
End Function
請建議我如何處理這...在此先感謝
是的,我已經使用了上面的函數,但我在Outlook中彈出一個窗口(請參閱上面提供的屏幕截圖),我怎樣才能通過VB腳本來處理這個問題。是否需要發送郵件的服務器地址,如果它需要然後如何提供smtp服務器地址和端口id到該腳本發送電子郵件到outlook由testcomplete –
要解決彈出我使用下面的代碼,但它得到運行時錯誤。設置omailWindow = Description.Create #here我得到運行時錯誤 omailWindow( 「標題」)值= emailcaption sTitle = 「稱號:=微軟Office Outlook中」。 如果窗口(omailWindow).Window(sTitle)。存在然後 Window(omailWindow).Window(sTitle).winbutton(「text =&Allow」)。點擊 EndIf請幫助我如何通過vb腳本處理彈出窗口 –