Can we change FROM email address while sending Outlook emails using vba

Gautham A

Board Regular
Joined
May 25, 2020
Messages
107
Office Version
  1. 2016
Platform
  1. Windows
Hi Team,
In my workplace, I have two mailboxes. One is my individual email I'd. Other is my team mailbox.(say TEAM A). While sending emails through Outlook in the from section, I will get option to put my team mail address. Now I'm writing a code to send email through Excel VBA. The problem here is the from section takes my individual mail address. I want my team mail I'd in FROM section. Is there a way to change it through Excel VBA?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try .SendUsingAccount and/or .SentOnBehalfOfName. Your code will look like:
VBA Code:
...
        With outMail
...
            .SendUsingAccount = "{email address}"
            .SentOnBehalfOfName = "{email address}"
...
            '.Display                                           ' Can change to Display instead of Send to test 
            .Send                                               ' Change to Send to send rather than display the draft message
        End With
A good resource to look at is Use the mail account you want in your mail macro
 
Upvote 0
i guess i must have access to the second account?
how does this work? .SentOnBehalfOfName =
 
Upvote 0
what's wrong with this that it wont send using a different account

Set OutlookApp = CreateObject("Outlook.Application")
Set OlObjects = OutlookApp.GetNamespace("MAPI")
Set newmsg = OutlookApp.CreateItem(olMailItem)

On Error Resume Next

newmsg.Recipients.Add (Cells(Target.Row, "Z").Value) ' Add Recipients
newmsg.Recipients.Add (Cells(Target.Row, "AA").Value)
newmsg.Subject = Cells(Target.Row, "B").Value & " Reimbursement" ' Add Subject
newmsg.Body = "This is to inform you that payment has been processed " & _
"on behalf of " & Cells(Target.Row, "B").Value & "." & vbCrLf & "" & _
"(If Check amount is greater than billed amount, this check contains multiple receipts and reimbursement requests.)"
newmsg.SendUsingAccount = "{mail@mail.org}" 'Send Email
 
Upvote 0
Hi Kenny

Still it is taking my individual email ID and not the team mailbox. I also ran sessions.accounts.count code. I got only one account. That is my individual mail address. Any reason why my team mailbox is not coming? While sending normal emails I'm able to put my team mailbox in FROM section. The problem occurs only while sending through Excel VBA
 
Upvote 0
Well you need to change newmsg.SendUsingAccount = "{mail@mail.org}" at least to newmsg.SendUsingAccount = "me@gmail.com" (i.e. whatever your email account is between the quotes).

As I said, try .SendUsingAccount and/or .SentOnBehalfOfName because although you may have ability to send using the group email you may only have rights on behalf of the account. Note I'm not an expert on this, however, my experience is that I see different behaviour depending on whether I am in my company's domain or at home.
 
Upvote 0
Hi Kenny
I have tried both .sendusingaccount and .sentonbehalfofname. It is still taking only my individual mail I'd. Any solution for this? Because I'm able to send mails normally through Outlook. Then why I'm not able to send through VBA? Any other methods?
 
Upvote 0
Hi team,
Any other methods as the above methods are not working for me?
 
Upvote 0
Hi, finally did you find a solution? I have exactly the same problem.
 
Upvote 0
no it fails or sends form my local open account
 
Upvote 0

Forum statistics

Threads
1,221,848
Messages
6,162,419
Members
451,764
Latest member
giannip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top