当我将电子邮件地址分配到To:,CC:和BCC:字段时,我必须分配To:字段,否则它会将cc或bcc放在To:字段中。
有了这个顺序的代码(To,BCC,CC) -
'These have to be 3, 2, 1 or else the BCC: or CC: shows up in the To: field of the email
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(RecipientList)
objOutlookRecip.Type = 1 ' 1 = olTo
'Add those who are being bcc'd on this email
Set objOutlookRecip = .Recipients.Add(bccList)
objOutlookRecip.Type = 3 ' 3 = olBCC
'Add those who are being cc'd on this email
Set objOutlookRecip = .Recipients.Add(ccList)
objOutlookRecip.Type = 2 ' 2 = olCC 这封电子邮件看起来如下:
To: = cc@cc.com
CC: = ""
BCC: = bcc@cc.com与此顺序的代码(To、CC、BCC)
'These have to be 3, 2, 1 or else the BCC: or CC: shows up in the To: field of the email
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(RecipientList)
objOutlookRecip.Type = 1 ' 1 = olTo
'Add those who are being cc'd on this email
Set objOutlookRecip = .Recipients.Add(ccList)
objOutlookRecip.Type = 2 ' 2 = olCC
'Add those who are being bcc'd on this email
Set objOutlookRecip = .Recipients.Add(bccList)
objOutlookRecip.Type = 3 ' 3 = olBCC 这封电子邮件看起来如下:
To: = bcc@cc.com
CC: = cc@cc.com
BCC: = ""使用此顺序的代码(BCC,CC,To)
'These have to be 3, 2, 1 or else the BCC: or CC: shows up in the To: field of the email
'Add those who are being bcc'd on this email
Set objOutlookRecip = .Recipients.Add(bccList)
objOutlookRecip.Type = 3 ' 3 = olBCC
'Add those who are being cc'd on this email
Set objOutlookRecip = .Recipients.Add(ccList)
objOutlookRecip.Type = 2 ' 2 = olCC
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(RecipientList)
objOutlookRecip.Type = 1 ' 1 = olTo 这封电子邮件发出的正确方式如下:
To: = ""
CC: = cc@cc.com
BCC: = bcc@cc.com另外,如果我想用cc:和/或bcc:(没有To:)发送电子邮件,我将得到
错误440:在“收件人”、“抄送”或“密件抄送”框中必须至少有一个名称或联系人。
我还有另外两个,为什么我会有这个错误呢?
我在消除错误的其他内容之前添加了这段代码:
If Len(RecipientList) = 0 Then
RecipientList = " "
End If这是调用例程:
SendTestHTMLMessages "to@to.com", "cc@cc.com:", "bcc@bcc.com", "Test Message Subject", "Test Message Body"这是工作代码:
Sub SendTestHTMLMessages(RecipientList As String, Optional ccList As String, Optional bccList As String, Optional Subject As String, Optional Body As String)
Dim objOutlook As Object ' Outlook.Application
Dim objOutlookMsg As Object ' Outlook.MailItem
Dim objOutlookRecip As Object ' Outlook.Recipient
Dim Signature As String
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
objOutlook.Session.Logon
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(0) '0 = olMailItem (Late Binding)
If Len(RecipientList) = 0 Then
RecipientList = " "
End If
With objOutlookMsg
'These have to be 3, 2, 1 or else the BCC: or CC: shows up in the To: field of the email
If Len(bccList) > 0 Then
'Add those who are being bcc'd on this email
Set objOutlookRecip = .Recipients.Add(bccList)
objOutlookRecip.Type = 3 ' 3 = olBCC
End If
If Len(ccList) > 0 Then
'Add those who are being cc'd on this email
Set objOutlookRecip = .Recipients.Add(ccList)
objOutlookRecip.Type = 2 ' 2 = olCC
End If
If Len(RecipientList) > 0 Then
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(RecipientList)
objOutlookRecip.Type = 1 ' 1 = olTo
End If
' Set the Subject & Body of the message.
.Subject = Subject
.htmlBody = Body
'.BodyFormat = 3 '3 = olFormatRichText
Set .SendUsingAccount = objOutlook.Session.Accounts.Item(1)
.Display
End With
End Sub 这感觉很疯狂,我想要理解它为什么会这样做。
发布于 2018-11-06 00:53:52
使用objOutlookRecip.Type =和objOutlookRecip.Resolve
或者objOutlookMsg.Recipients.ResolveAll就在End With之后。
https://stackoverflow.com/questions/53161938
复制相似问题