我的用户将其个人邮箱作为其主要帐户,并在其Outlook 2010客户端中配置了自动映射的共享邮箱。共享邮箱是Office 365共享邮箱,因此无法登录以将其设置为主帐户。
我正在尝试从共享帐户的地址开始发送新电子邮件。
以下是我一直在尝试使用的VBA代码。我在Outlook的信任中心设置中允许使用宏。
Public Sub New_Mail()
Dim oAccount As Outlook.Account
Dim oMail As Outlook.MailItem
For Each oAccount In Application.Session.Accounts
If oAccount = "sharedMailboxAddress@domain.tld" Then
Set oMail = Application.CreateItem(olMailItem)
oMail.SendUsingAccount = oAccount
oMail.Display
End If
Next
End Sub
答案 0 :(得分:1)
委托邮箱不在Namespace.Accounts列表中。
改为设置MailItem.SentOnBehalfOfName
属性。
答案 1 :(得分:0)
什么在您的代码中不起作用?
使用smtpAddress
属性选择一个帐户。
示例功能:
Private Function GetAccountForEmailAddress(smtpAddress As String) As Outlook.account
Dim account As Outlook.account
For Each account In Application.Session.accounts
If LCase(account.smtpAddress) = LCase(smtpAddress) Then
Set GetAccountForEmailAddress = account
Exit Function
End If
Next account
MsgBox "No Account with SmtpAddress: " & smtpAddress & " exists!", vbCritical, "Oops!"
Set GetAccountForEmailAddress = Nothing
End Function
答案 2 :(得分:0)
debug.print行将显示帐户。
Option Explicit
Public Sub New_Mail()
Dim oAccount As account
Dim oMail As mailItem
For Each oAccount In Session.Accounts
Debug.Print oAccount
If LCase(oAccount) = LCase("text copied from the immediate window") Then
Set oMail = CreateItem(olMailItem)
oMail.SendUsingAccount = oAccount
oMail.Display
End If
Next
ExitRoutine:
Set oMail = Nothing
End Sub
答案 3 :(得分:0)
将以下代码与SentOnBehalfOfName属性一起使用可从共享邮箱的地址启动新电子邮件。感谢Dmitry Streblechenko指出我正确的方向。
Sub New_Mail()
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
With objMsg
.SentOnBehalfOfName = "sharedMailboxAddress@domain.tld"
.Display
End With
Set objMsg = Nothing
End Sub