Sending email from other account

I send emails through Outlook using Excel VBA. I am using my work computer with my work email as the main account, but want to send from another account that is logged in.

I have not managed to integrate any of the code found online.

The below code is without my attempt of fixing it.

Sub Test1()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim cell As Range
    Dim strbody As String
    For Each cell In Range("D2:D2")
        strbody = strbody & cell.Value & vbNewLine

    Application.ScreenUpdating = False
    Set OutApp = CreateObject("Outlook.Application")

    On Error GoTo cleanup
    For Each cell In Columns("A").Cells.SpecialCells(xlCellTypeConstants)
        If cell.Value Like "?*@?*.?*" And _
           LCase(Cells(cell.Row, "C").Value) = "yes" Then

            Set OutMail = OutApp.CreateItem(0)
            On Error Resume Next
            With OutMail
                .To = cell.Value
                .Subject = "A personal message from the founder"
                .Body = "Hi " & Cells(cell.Row, "B").Value & vbNewLine & vbNewLine & strbody
            End With
            On Error GoTo 0
            Set OutMail = Nothing
        End If
    Next cell

    Set OutApp = Nothing
    Application.ScreenUpdating = True
End Sub

2 answers

  • answered 2022-01-19 16:49 steveP

    Do you mean send from another email address? If so just add :

    .SentOnBehalfOfName = "" 'Change to the email address you want to send from


    With OutMail
                .To = cell.Value
                .SentOnBehalfOfName = ""
                .Subject = "A personal message from the founder"
                .Body = "Hi " & Cells(cell.Row, "B").Value & vbNewLine & vbNewLine & strbody
            End With

  • answered 2022-01-19 17:11 Eugene Astafiev

    There are two possible ways in Outlook:

    1. If another account is configured in Outlook you need to use the MailItem.SendUsingAccount property which returns or sets 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 ("") 
     Set oMail.SendUsingAccount = oAccount 
     End If 
    End Sub
    1. If you have got permissions set by the Exchange admin to send on behalf of another person you need to use the MailItem.SentOnBehalfOfName property which returns a string indicating the display name for the intended sender of the mail message.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum