51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1108|回复: 2
打印 上一主题 下一主题

[原创] 【seagull1985-QTP】利用outlook进行邮件发送并添加附件

[复制链接]
  • TA的每日心情
    奋斗
    2018-8-27 15:56
  • 签到天数: 322 天

    连续签到: 1 天

    [LV.8]测试军长

    跳转到指定楼层
    1#
    发表于 2016-3-14 18:29:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    利用outlook进行邮件发送并添加附件
    1. '==========================================================================
    2. ' NAME: mail
    3. ' AUTHOR: heyl  
    4. ' DATE  : 2013-03-13
    5. ' Last Update :2013-07-24
    6. ' COMMENT:  
    7. '==========================================================================
    8. Class MailEngine

    9.         Public objOutlook
    10.         Public objOutlookMsg
    11.         Public olMailItem
    12.        
    13.         Private Sub Class_Initialize   
    14.         ' Create the Outlook object and the new mail object.
    15.         Set objOutlook = CreateObject("Outlook.Application")
    16.         Set objOutlookMsg = objOutlook.CreateItem(olMailItem)   
    17.         End Sub
    18.        
    19.         Private Sub Class_Terminate       
    20.         ' Release the objects
    21.         Set objOutlook = Nothing
    22.         Set objOutlookMsg = Nothing
    23.         Set olMailItem = Nothing       
    24.         End Sub
    25.                
    26.         Public Function AttachmentExist(filepath)
    27.            Dim fso
    28.        Set fso = CreateObject("Scripting.FileSystemObject")
    29.            AttachmentExist = fso.FileExists(filepath)
    30.            Set fso = nothing
    31.         end Function
    32.        
    33.         Public Function SendMail(str_subject,str_body,str_to,str_cc)
    34.                 objOutlookMsg.To = str_to
    35.         objOutlookMsg.CC = str_cc
    36.                 objOutlookMsg.Subject = str_subject
    37.         objOutlookMsg.Body = str_body
    38.            Dim str_attachment
    39.            '添加附件路径
    40.            str_attachment = str_Test_Path&"Report\"&GetTestName&"\Result.xls"
    41.            path_attachment = str_Test_Path&"Report\"&GetTestName
    42.                 If AttachmentExist(str_attachment) Then
    43.                  'Create FileSystemObject
    44.                   Set MyFileObject = CreateObject("Scripting.FileSystemObject")   
    45.                   'Create Folder object,get attachment count
    46.                   Set MyFolder = MyFileObject.GetFolder(path_attachment)
    47.                   For Each thing in MyFolder.Files
    48.                     thing = Cstr(thing)
    49.                         'ADD other Attachments
    50.                         If ".xls" <> Right(thing,4) Then
    51.                     objOutlookMsg.Attachments.add(thing)
    52.                         End If
    53.                   Next
    54.                   'ADD xls Attachments
    55.                   objOutlookMsg.Attachments.add(str_attachment)
    56.         End If
    57.         'Display the email
    58.         objOutlookMsg.Display
    59.         ' Send the message
    60.         objOutlookMsg.Send      
    61.      end Function
    62.        
    63. End Class

    64. 'Set oMailEngne = new  MailEngine
    65. 'Call oMailEngne.SendMail("自动化测试结果通知邮件标题","自动化测试结果通知邮件内容","XXX@qq.com","")
    复制代码


    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-9-23 15:34 , Processed in 0.069147 second(s), 22 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表