我正在尝试整理一个群发电子邮件宏,它将遍历表格,提取电子邮件和收件人姓名。出于品牌推广的目的,我想向每封电子邮件发送签名。
我正在尝试使用MailItem对象,但我遇到了两个问题:
.display会创建一个新的Outlook电子邮件,并使用默认签名填充它。但是,.body将使用strMessage中的文本字符串擦除签名。我猜它是因为我不能在同一个电子邮件对象中同时拥有一个表(包括图片等)和字符串?
我在Microsoft Outlook 15和16个Object库上都尝试过.send和.body方法。虽然两者都在16上工作,但似乎在15中都不存在。我总是给出“应用程序定义的或对象定义的错误”。我找不到任何关于Outlook 15库的文档,是否有人知道15与.send和.body相同的方法?
Dim OApp As Object, OMail As Object, signature As String
Set OApp = CreateObject("Outlook.Application")
Set OMail = OApp.CreateItem(0)
Dim rs As DAO.Recordset
Dim db As Database
Dim strSQL As String, strFirstName As String, strLastName As String, strFullName As String, strSubject As String, strMessage As String
Set db = CurrentDb
strSQL = "SELECT Email, FirstName, LastName FROM PersonsT WHERE [PersonsT]![Attended]=True"
Set rs = db.OpenRecordset(strSQL)
Do While Not rs.EOF
strFirstName = rs.Fields("FirstName")
strLastName = rs.Fields("LastName")
strFullName = rs.Fields("FirstName") & " " & rs.Fields("LastName")
strSubject = "Greetings"
strMessage = "Hello " & strFullName & vbNewLine & vbCrLf & " Let me be the first to congratulate you on registering in this program"
With OMail
.Display
End With
With OMail
.to = rs![Email]
.Subject = strSubject
.body = strMessage
.send
End With
rs.MoveNext
Loop
Set OMail = Nothing
Set OApp = Nothing
rs.Close
Set rs = Nothing
答案 0 :(得分:1)
考虑使用MailItem的GetInspector()属性预先检索签名文本,然后连接到邮件正文。渲染可能会有所不同,因此请在两行中.HTMLBody
而不是.Body
:
...
Dim signature As String
oMail.GetInspector
signature = oMail.Body
With OMail
.Recipients.Add rs![Email]
.Subject = strSubject
.Body = strMessage & signature
.Display
End With
答案 1 :(得分:0)
这适用于各种各样的outlook,并使用后期绑定,所以版本/引用不应成为问题。
Dim OutApp As Object
Dim OutMail As Object
Dim signature As String
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail ' This creates a blank email and captures the users default signature.
.BodyFormat = 2 'olFormatHTML
.Display
End With
signature = OutMail.HTMLBody