0

I go into a shared inbox and forward an email as myself, to my boss, using HTML formatting.

I wrote VBA code that works on every step except changing the From line from the shared mailbox email address to my email address.

Let's call my personal email address "gwyn@email.com" and the shared mailbox email address "office@email.com". If I manually click on the From field I can select my own email address and send it.

Public Sub ForwardIAF()
    Dim OutApp As Object
    Dim OutAccount As Outlook.Account
    Dim myinspector As Outlook.Inspector
    Dim myIAF As Outlook.MailItem
    Dim myForward As Outlook.MailItem
    
    Set myIAF = GetCurrentItem()
    Set myForward = myIAF.Forward
    Set OutApp = CreateObject("Outlook.Application")
    Set OutAccount = OutApp.Session.Accounts.Item(1)
    With myForward
        .SentOnBehalfOfName = "gwyn@email.com"
        Debug.Print "myForward.SentOnBehalfOfName:" & "x " & myForward.SentOnBehalfOfName & " x"
        .Recipients.Add "gwyn@email.com"
        .BodyFormat = olFormatHTML
        .Display
    End With
End Sub

When the forward opens, it shows my email address in the From line, but when I send, it reverts to the office email address. The debug print shows my email address is in the .SentOnBehalfOf field, so it looks like it's there until it sends.

Replacing .Display with .Send has the same result.

Community
  • 1
  • 1
  • When mail is sent manually does the recipient see "On Behalf Of"? – niton Feb 03 '22 at 13:12
  • i dont believe so, no. I don't think i've ever seen an email come in/go out with "on behalf of", so i'm not sure i'd recognize it. when i manually send an email from the office inbox using my email in the "from" field, it looks like it came from my account, with my name and icon and address like normal. – dolichomorph Feb 04 '22 at 17:20
  • When you ask for permission be sure to emphasize you want "on behalf of" not "as". https://support.microsoft.com/en-us/topic/how-to-grant-exchange-and-outlook-mailbox-permissions-in-office-365-dedicated-bac01b2c-08ff-2eac-e1c8-6dd01cf77287 and https://learn.microsoft.com/en-us/microsoft-365/admin/add-users/give-mailbox-permissions-to-another-user?view=o365-worldwide – niton Feb 04 '22 at 17:46
  • Your question is confusing. It seems backwards. You might confirm what you want with https://www.eduhk.hk/ocio/content/faq-how-send-mail-behalf-another-user. It is possible you want send "As". – niton Feb 04 '22 at 18:21
  • Does this answer your question? [Switching the FROM Inbox](https://stackoverflow.com/questions/62729844/switching-the-from-inbox) – niton Feb 04 '22 at 18:42
  • I believe what you want is a an account for "office@email.com". https://support.microsoft.com/en-us/office/add-an-email-account-to-outlook-6e27792a-9267-4aa4-8bb6-c84ef146101b so you can use `.SendUsingAccount`. You will see from the suggested duplicate Outlook sometimes requires **Set** in `Set .SendUsingAccount = acc`. – niton Feb 04 '22 at 18:47

1 Answers1

0

The SentOnBehalfOfName property makes sense only in case of Exchange profiles/accounts. Moreover, you need to have the required permissions to send on behalf of another person. See Issue with SentOnBehalfOfName for a similar discussion.

In case if you have multiple accounts configured in the profile you can use the SendUsingAccount property which allows to an Account object that represents the account under which the MailItem is to be sent.

 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 
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • I've tried using SendUsingAccount as well, it still gives a similar issue. It looks like it will use my email address, but actually sends with the office email. I don't think my permissions are the issue, since I can send from my email address by clicking manually. Also, I don't think I need permission to send as *myself*? – dolichomorph Feb 02 '22 at 18:38
  • You need to set the `SendUsingAccount` to the account, not string like in your code listed. – Eugene Astafiev Feb 02 '22 at 20:16
  • Also to be able to use the `SendUsingAccount` property in the code you need to have both accounts configured in the same Outlook profile. – Eugene Astafiev Feb 02 '22 at 20:17