(1)可以在excel中维护邮件主题、内容,并将不同附件添加到不同的邮件地址,实现批量对不同的人发送不同的邮件。(2)修订了原程序,可以先将邮件保存到草稿箱,检查后在发送。(3)注:不同附件的生成请另程序编写
Public Function SendMail(strFrom As String, strTo As String, _
strCC As String, _
strBCC As String, _
strSubject As String, _
strBody As String, _
strFilename As String _
) As Boolean
Dim oOutlookApp As New Outlook.Application
Dim oItemMail As Outlook.MailItem
Set oItemMail = oOutlookApp.CreateItem(olMailItem)
On Error GoTo errHandle
If Len(Trim(strFilename)) = 0 Then
With oItemMail
'.Recipients
.SentOnBehalfOfName = strFrom
.To = strTo
.CC = strCC
.BCC = strBCC
.Subject = strSubject
.Body = strBody
'.Attachments.Add (strFilename)
.Importance = olImportanceHigh
.Sensitivity = olPersonal
.Send
End With
Else
With oItemMail
'.Recipients
.SentOnBehalfOfName = strFrom
.To = strTo
.CC = strCC
.BCC = strBCC
.Subject = strSubject
.Body = strBody
.Attachments.Add (strFilename)
.Importance = olImportanceHigh
.Sensitivity = olPersonal
.Send
End With
End If
SendMail = True
Exit Function
errHandle:
SendMail = False
End Function
Public Function CheckMail(strFrom As String, strTo As String, _
strCC As String, _
strBCC As String, _
strSubject As String, _
strBody As String, _
strFilename As String _
) As Boolean
Dim oOutlookApp As New Outlook.Application
Dim oItemMail As Outlook.MailItem
Set oItemMail = oOutlookApp.CreateItem(olMailItem)
On Error GoTo errHandle
If Len(Trim(strFilename)) = 0 Then
With oItemMail
'.Recipients
.SentOnBehal
fOfName = strFrom
.To = strTo
.CC = strCC
.BCC = strBCC
.Subject = strSubject
.Body = strBody
'.Attachments.Add (strFilename)
.Importance