'Send from another email address in Outlook

My users have their personal mailbox as their primary account and an auto-mapped shared mailbox configured in their Outlook 2010 client. The shared mailbox is an Office 365 shared mailbox and thus cannot be logged into to set it as the primary account.

I am trying to start a new email from the shared account's address.

Below is the VBA code I have been trying to use. I have allowed Macros in Outlook's trust center settings.

Public Sub New_Mail()
Dim oAccount As Outlook.Account
Dim oMail As Outlook.MailItem
For Each oAccount In Application.Session.Accounts
    If oAccount = "[email protected]" Then
        Set oMail = Application.CreateItem(olMailItem)
        oMail.SendUsingAccount = oAccount
        oMail.Display
    End If
Next
End Sub


Solution 1:[1]

Using the following code with the SentOnBehalfOfName property starts a new email from the shared mailbox's address. Thanks to Dmitry Streblechenko for pointing me in the right direction.

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

Solution 2:[2]

A delegate mailbox will not be in the Namespace.Accounts list.

Set the MailItem.SentOnBehalfOfName property instead.

Solution 3:[3]

What does not work in your code?

Use the smtpAddress property to select an account.

Example function:

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

Solution 4:[4]

The debug.print line will show you the accounts.

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

Solution 5:[5]

Not exactly the problem I had, but this question and the answers helped. My problem was to send from a particular mailbox while using many accounts. The one-liner answer was this:

OutMail.SendUsingAccount = OutApp.Session.Accounts.Item("[email protected]")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dino Padilla
Solution 2
Solution 3 Axel Kemper
Solution 4 niton
Solution 5 AndrĂ¡s