使用vbs发送email的模板

sub includeFile (fSpec)
    dim fileSys, file, fileData
    set fileSys = createObject ("Scripting.FileSystemObject")
    set file = fileSys.openTextFile (fSpec)
    fileData = file.readAll ()
    file.close
    executeGlobal fileData
    set file = nothing
    set fileSys = nothing
end sub

includeFile "body.vbi"

' sdt 为今日日期的字符串,比如 '2010-12-9',可用于附件名字里
sdt = FormatDateTime(Date)

' 注意:以单引号'开头的行为注释
' receiptions 为收件人列表,多个收件人之间用分号隔开
' Subject 为邮件标题
' Body 为邮件正文
' Attachments 为附件列表,每个附件都需附带路径。

receiptions = "[email protected]"
Subject = "报告 " & sdt
Body = exBody
Attachments = Array("E:\q.gif","E:\code\python\bug.gif")

' 以下代码无需修改
Dim xOutLook
Dim xMail

On Error Resume Next
Set xOutLook = GetObject(, "Outlook.Application")
If xOutLook Is Nothing Then
    Set xOutLook = CreateObject("Outlook.Application")
End If
Set xMail = xOutLook.CreateItem(olMailItem)
With xMail
    .Display
    Dim signature
    signature = .HTMLBody
    .To = receiptions
    .Subject = Subject
    .HTMLBody = Body
    .Importance = olImportanceNormal    ' 设置优先级, olImportanceHigh为高优先级

    Dim xDoc
    Set xDoc = xMail.Application.ActiveInspector.WordEditor

    If IsArray(Attachments) Then
        Dim attachment
        For Each attachment In Attachments
            .Attachments.Add attachment
        Next
    End If

    .HTMLBody = .HTMLBody & signature

    attach1 = "E:\test.txt"
    Dim fso, objFile
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set objFile = fso.GetFile(attach1)
    If objFile.Size > 0 Then
	    .Attachments.Add attach1
    End if	    
    .Send    
End With

 

你可能感兴趣的:(使用vbs发送email的模板)