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中添加新电子邮件帐户。