在VBA中实现通过Outlook发送邮件

1.添加引用Microsoft Outlook 11.0 Object Library。(这里用的是Microsoft Outlook 2003)
 
2.定义发送邮件过程。
Public Sub SendEmail(Receiver As String, SubjectText As String, BodyText As String, AttachedObject As String)
    Dim OutlookApp As Outlook.Application
    Dim OutlookItem As Outlook.MailItem
   
    Set OutlookApp = New Outlook.Application
    Set OutlookItem = OutlookApp.CreateItem(olMailItem)
   
On Error GoTo SendEmail_Error
    With OutlookItem
        .To = Receiver '收件人地址
        .Subject = SubjectText '邮件主题
        .Body = BodyText '邮件内容
        .Attachments.Add AttachedObject '粘贴附件
        .Send '发送邮件
    End With
SendEmail_Exit:
    Exit Sub
  
SendEmail_Error:
    MsgBox Err.Description
    Resume SendEmail_Exit
End Sub
 
3.调用发送邮件过程。
    SendEmail " jmfrd@126.com", "需求分析", "现有一项目需开发,详情请见附件。", "E:/需求分析.doc"
 
4.在Outlook中添加新电子邮件帐户。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值