vba - 在每封发送的电子邮件上设置 .SentOnBehalfofName

标签 vba outlook outlook-2016

我正在尝试为通过 Outlook 2016 发送的每封电子邮件设置 .SentOnBehalfOfName。也就是说,每当我点击“新邮件”、“回复”、“全部回复”或“转发”时。

我试过这个:

Public WithEvents myItem As Outlook.MailItem

Private Sub Application_ItemLoad(ByVal Item As Object)
    If (TypeOf Item Is MailItem) Then
        Set myItem = Item
    End If
End Sub


Private Sub FromField()

With myItem
    .SentOnBehalfOfName = "example@aol.com"
    .Display
End With

End Sub


Private Sub myItem_Open(Cancel As Boolean)

    FromField

End Sub

最佳答案

SentOnBehalfOfName属性仅在 Exchange 配置文件/帐户的情况下才有意义。此外,您需要具有代表其他人发送所需的权限。参见 Issue with SentOnBehalfOfName进行类似的讨论。

如果您在配置文件中配置了多个帐户,您可以使用 SendUsingAccount允许一个帐户对象的属性,该对象表示要发送 MailItem 的帐户。

 Sub SendUsingAccount() 
  Dim oAccount As Outlook.account 
  For Each oAccount In Application.Session.Accounts 
   If oAccount.AccountType = olPop3 Then 
    Dim oMail As Outlook.MailItem 
    Set oMail = Application.CreateItem(olMailItem) 
    oMail.Subject = "Sent using POP3 Account" 
    oMail.Recipients.Add ("someone@example.com") 
    oMail.Recipients.ResolveAll 
    oMail.SendUsingAccount = oAccount 
    oMail.Send 
   End If 
  Next 
 End Sub 

关于vba - 在每封发送的电子邮件上设置 .SentOnBehalfofName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33331320/

相关文章:

excel - 使用前面的单元格值自动更新范围中的空白单元格

vba - Outlook VBA - 在电子邮件中打开链接时是否触发了事件?

outlook - 如何在 Outlook 2016 中查看电子邮件的 HTML 源代码

python win32com outlook,无法检索发件人信息。

c# - 附件未出现在 Outlook 2016 中

c# - Outlook 2016 插件 AttachmentSelection 问题

excel - ReDim Preserve 停止在 Excel VBA 代码中工作

excel - 优化 VBA Excel 打印 - 创建 PDF?

vba - 在 Column 中查找相同的数据并将其过滤到另一个工作表

batch-file - 通过 Outlook 发送电子邮件的 DOS 批处理 : need to add new lines