VBA利用outlook发送邮件

该篇文章详细描述了一个使用VBA编写的Outlook16.0ObjectLibrary的示例代码,演示如何通过宏功能发送带有附件的电子邮件,包括设置收件人、抄送、主题和文件路径。
摘要由CSDN通过智能技术生成

工具引用:Microsoft Outlook 16.0 Object Librar

示例代码:

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 = "xxx@xxx.com"        '收件人
        .CC = "xxx@xxx.com"      '抄送
        .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  = "xxx@xx.com"  '发送人
        ' .Send                  '发送
    End With
    Set objMail = Nothing
    Set objOutlook = Nothing
End Sub
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值