当我将电子邮件地址分配给to:、CC:和BCC:字段时,我必须最后分配to:字段,否则它会将抄送或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
按此顺序编码(收件人、抄送、密件抄送(
'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
这感觉很糟糕,我想了解它为什么会这样做。
使用objOutlookRecip.Resolve
跟随objOutlookRecip.Type =
或紧接在CCD_ 4之后的CCD_。