QTP中发送邮件

来源:互联网 发布:潜意识的力量 知乎 编辑:程序博客网 时间:2024/04/28 08:30

Public Function Bug_SendByOutLook(emailAddress,subject,body,attachment)
  If (emailAddress="" Or subject="" ) Then
      Call LogFile("Function SendMailBySMTP","Error","Enter Argument Error")
      Exit Function
  Else  
      body=BugFormat()
      Set objOutlook = CreateObject("Outlook.Application")
      Set myNameSpace = objOutlook.GetNameSpace("MAPI")
      'objOutlook.Outlook.Application.Visible = True
     'Sends an email to sanjay
   Dim SendItem
      Set SendItem = objOutlook.CreateItem(0)
   SendItem.Recipients.Add emailAddress
   SendItem.Subject = subject
   SendItem.Body = body
   If attachment<>"" Then
     SendItem.Attachments.Add(attachment)
   End If
    SendItem.Send
    Set myNameSpace=Nothing
    Set objOutlook=Nothing
 End If
End Function

Public Function Bug_SendBySMTP(strFrom,strTo,subject,body,attachment,attr_name)
  If (emailAddress="" Or subject=""  ) Then
      Call logFile("Function SendMailBySMTP","Error","Enter Argument Error")
      Exit Function
  Else   
      Set objSendMail = CreateObject("CDONTS.NewMail")
      objSendMail.From = strFrom
      objSendMail.To = strTo
      objSendMail.Subject = subject
      objSendMail.Body = body
      If attachment<>"" And attr_name<>"" Then
          objSendMail.AttachFile attachment,attr_name
      End If
      objSendMail.Send
      Set objSendMail = Nothing
  End If
End Function

 

原创粉丝点击