首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用CC: Field和/或BCC: field与no : field,电子邮件地址放在: field

使用CC: Field和/或BCC: field与no : field,电子邮件地址放在: field
EN

Stack Overflow用户
提问于 2018-11-05 20:45:21
回答 1查看 505关注 0票数 0

当我将电子邮件地址分配到To:,CC:和BCC:字段时,我必须分配To:字段,否则它会将cc或bcc放在To:字段中。

有了这个顺序的代码(To,BCC,CC) -

代码语言:javascript
复制
'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 

这封电子邮件看起来如下:

代码语言:javascript
复制
To: = cc@cc.com  
CC: = ""  
BCC: = bcc@cc.com

与此顺序的代码(To、CC、BCC)

代码语言:javascript
复制
'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  

这封电子邮件看起来如下:

代码语言:javascript
复制
To: = bcc@cc.com  
CC: = cc@cc.com  
BCC: = ""

使用此顺序的代码(BCC,CC,To)

代码语言:javascript
复制
'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 

这封电子邮件发出的正确方式如下:

代码语言:javascript
复制
To: = ""  
CC: = cc@cc.com  
BCC: = bcc@cc.com

另外,如果我想用cc:和/或bcc:(没有To:)发送电子邮件,我将得到

错误440:在“收件人”、“抄送”或“密件抄送”框中必须至少有一个名称或联系人。

我还有另外两个,为什么我会有这个错误呢?

我在消除错误的其他内容之前添加了这段代码:

代码语言:javascript
复制
If Len(RecipientList) = 0 Then
    RecipientList = " "
End If

这是调用例程:

代码语言:javascript
复制
SendTestHTMLMessages "to@to.com", "cc@cc.com:", "bcc@bcc.com", "Test Message Subject", "Test Message Body"

这是工作代码:

代码语言:javascript
复制
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 

这感觉很疯狂,我想要理解它为什么会这样做。

EN

回答 1

Stack Overflow用户

发布于 2018-11-06 00:53:52

使用objOutlookRecip.Type =objOutlookRecip.Resolve

或者objOutlookMsg.Recipients.ResolveAll就在End With之后。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53161938

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档