VBA利用outlook发送邮件

工具引用:Microsoft Outlook 16.0 Object Librar

VBA利用outlook发送邮件_第1张图片

示例代码:

Attribute VB_Name = "模块1"
Option Explicit
Sub sendEmail()
    Dim objOutlook As Outlook.Application
    Dim objMail As MailItem
    Dim strFilePath As String

    Set objOutlook = New Outlook.Application '创建objOutlook为Outlook应用程序对象
    Set objMail = objOutlook.CreateItem(olMailItem)  '创建objMail为一个邮件对象
    
    With objMail
        .To = "[email protected]"        '收件人
        .CC = "[email protected]"      '抄送
        .Subject = "this is a test"        '标题
        .Body = "Test for auto send email"           '正文
        ' 获取当前工作目录路径
        strFilePath = ThisWorkbook.Path & "\test_import.txt"
        .Attachments.Add strFilePath,olByValue, 1, "4th Quarter 1996 Results Chart"  '附件   
        .Save               '保存为草稿
        .SentOnBehalfOfName  = "[email protected]"  '发送人
        ' .Send                  '发送
    End With
    Set objMail = Nothing
    Set objOutlook = Nothing
End Sub

你可能感兴趣的:(outlook,ui,前端)