0

在 UFT 中,我使用 VBScript 编写了电子邮件功能,但电子邮件没有从我的邮箱触发。它是从 SBGalert@.co.za 触发的,而我也提到了来自地址。

请协助我修复电子邮件以从我的邮箱触发到利益相关者。我正在使用 Outlook 15。

请在下面找到我的代码以进行检查和帮助。

Function Email
'Dim ToAddress
'Dim Subject
'Dim Body
Dim Attachment
Dim oUtlookApp, nAmeSpace, newMail
Dim fso, TextFile

SystemUtil.Run "C:\Program Files\Microsoft Office 15\root\office15\OUTLOOK.EXE" 'This line should be enabled if the Outlook on the desktop is not running
If strMailID_From <> "abc@<abc>.co.za" Then
FromAddress = strMailID_From
Else
FromAddress = "abc@<abc>.co.za"
End If

ToAddress = "abc@<abc>.co.za" ' Message recipient Address

Set oUtlookApp = CreateObject("Outlook.Application")
Set nAmeSpace = oUtlookApp.GetNamespace("MAPI")
Set newMail = oUtlookApp.CreateItem(1)

Subject = "This is a test mail" 'Message Subject you can update

'For Creating File System Object
Set fso = Createobject ("Scripting.FileSystemObject")

'For Opening the Report File in Append Mode
Set TextFile = fso.OpenTextFile(strPath & "results.html" , 8, True)
strExecutionTimeFormate=Replace(strExecutionTime,"-",":")
TextFile.Write "<html><head><title>VAF -S2K - Automation Execution Consolidated Result</title></head>"
TextFile.Write "<body bgcolor=#3D5FA3><table width=100% bgcolor=#FFFFFF border=2 cellpadding=2 cellspacing=1>"
TextFile.Write "<tr bgcolor=#CBD9F4></td><td bgcolor=#CBD9F4 width = 100%><div align=center><font color=purple><font size=5><p><strong>Automation Execution Consolidated Results</strong></p><font color=purple><font size=5><p><strong><font size=3>Execution Date -"&strExecutionDate&"  Execution Time :"&strExecutionTimeFormate&" [HH:MM:SS]</strong></p></td></div></tr>"
TextFile.Write "<body bgcolor=#3D5FA3><table width=100% bgcolor=purple border=1 cellpadding=3 cellspacing=1>"
TextFile.Write "<tr bgcolor=#CBD9F4></td><td bgcolor=#CBD9F4 width = 100%><div align=center><font color=purple><font size=5><font size=3><p><strong>Portfolio : VAF &nbsp || &nbsp Application  : S2K &nbsp || &nbsp Environment : SIT 1 &nbsp || &nbsp Project : Sanity Testing</strong></td></Table>"
TextFile.Write "<body bgcolor=#3D5FA3><table width=100% bgcolor=purple border=1 cellpadding=3 cellspacing=1>"
TextFile.Write "<tr><td bgcolor=white width = 20%><div align=Center><font color=Black><strong>APPLICATION</td><td bgcolor=white width = 45%><div align=Center><font color=Black><strong>TEST CASE NAME</td><td bgcolor=white width = 20%><div align=Center><font color=Black><strong>TEST CASE STATUS</td><td bgcolor=white width = 15%><div align=Center><font color=Black><strong>RUN TIME</td></Table>"
TextFile.Write "<body bgcolor=#3D5FA3><table width=100% bgcolor=purple border=1 cellpadding=3 cellspacing=1>"
'|| &nbsp Cycle : 1 &nbsp
'TextFile.Write "<tr bgcolor=#IBD9F4></td><td bgcolor=#IBD9F4 width = 100%><div align=center><font color=purple><font size=5><p><strong>Automation Execution  Consolidated Results</strong></p><font color=purple><font size=5><p><strong><font size=3>Execution Date -"&strExecutionDate&"  Execution Time :"&strExecutionTimeFormate & "</strong></p><font color=purple><font size=3><p><strong>Portfolio : Self Service Channel     Application  : Internet Banking     Cycle : 1     Project : Regression Testing</strong></td></div></tr>"
TextFile.Close

newMail.Subject = Subject
newMail.Body = Body
newMail.Recipients.Add(ToAddress)
newMail.Attachments.Add(strPath & "results.html") 'You can update attachment file name
newMail.Send
Set nAmeSpace = Nothing
Set oUtlookApp = Nothing

End Function
4

1 回答 1

0

如果您未指定要发送的帐户,它将默认为您的第一个邮箱。

我使用字典对象EmailData来指定我发送的电子邮件的详细信息UFT。如果您希望从特定邮箱发送邮件,您需要识别相关邮箱并将MailItem's设置为您想要的邮箱.SendUsingAccount

如果传入字典中的条目为空白,则默认为发送用户有权访问的第一个帐户(通常是他们的个人帐户)。否则,它会遍历帐户以查找它应该使用的邮箱。如果不存在,则退出并报告用户无权访问所需邮箱。

否则,它mailitem会在构建时设置要发送的地址。

如果您在这方面需要任何进一步的帮助,请告诉我?

If EmailData("SendFrom") = "" Then
    ' default to first email account the user has access to
    LOG_Write "Send From value is not set; defaulting to user's personal mail account to send from."
    iAccount = 1
Else
    LOG_Write "Checking to see if the account to send from is accessible by this user..."
    iAccount = 0
    For iLoop = 1 To oOutlook.Session.Accounts.Count
        If UCase(Trim(oOutlook.Session.Accounts.Item(iLoop))) = UCase(Trim(EmailData("SendFrom"))) Then
            iAccount = iLoop
            Exit For
        End If
    Next
    If iAccount = 0 Then
        sErrorMsg = "Cannot send email from specified account: " & EmailData("SendFrom") & " as this user doesn't appear to have access to it in Outlook!"
        LOG_Write sErrorMsg
        OL_SendMail = False
        Exit Function
    End If
End If

Dim oMailItem : Set oMailItem = oOutlook.CreateItem(olMailItem)
With oMailItem
    Set .SendUsingAccount = oOutlook.Session.Accounts.Item(iAccount)
    .To = EmailData("To")
    .CC = EmailData("CC")
    .BCC = EmailData("BCC")
    .Subject = EmailData("Subject")
    .Body = EmailData("Body")
    sAttachArray = Split(EmailData("AttachmentPaths"), ";")
    For Each sAttachment In sAttachArray
        .Attachments.Add(sAttachment)
    Next
    .Recipients.ResolveAll
    .Display    ' debug mode - uncomment this to see email before it's sent out
End With
于 2017-06-29T12:15:37.143 回答