2015-12-02 86 views
0

我的用户将其个人邮箱设为主帐户,并在其Outlook 2010客户端中配置自动映射的共享邮箱。共享邮箱是Office 365共享邮箱,因此无法登录将其设置为主帐户。从Outlook中的其他电子邮件地址发送

我试图从共享帐户的地址开始一封新邮件。

下面是我一直在尝试使用的VBA代码。我在Outlook的信任中心设置中允许使用宏。

+0

VB.NET与VBA/Office宏无关。 – varocarbas

回答

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 
+0

当我尝试运行我的代码时,没有任何反应,也没有发生错误。我在代码上面添加了你的函数,运行时仍然没有任何反应。 –

+0

Marc一行代码启动VBA调试器,一旦VBA行被执行。可能是找出发生的唯一方法。 –

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 
1

委托邮箱将不在Namespace.Accounts列表中。

改为设置MailItem.SentOnBehalfOfName属性。

+0

使用此属性允许它正常工作。 –

0

对SentOnBehalfOfName属性使用以下代码将从共享邮箱的地址中启动一封新邮件。感谢德米特里Streblechenko指出我在正确的方向。

Sub New_Mail() 
Dim objMsg As MailItem 
Set objMsg = Application.CreateItem(olMailItem) 


With objMsg 
    .SentOnBehalfOfName = "[email protected]" 
    .Display 
End With 

Set objMsg = Nothing 
End Sub 
相关问题