• Outlook User
  • Exchange Admin
  • Office 365
  • Outlook Developer
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
    • Common Problems
    • Outlook BCM
    • Utilities & Addins

Macros to send messages using a specific account

Slipstick Systems

› Developer › Macros to send messages using a specific account

Last reviewed on August 12, 2020     51 Comments

Outlook 2013 and up have an option to always send new messages using the default email account.

Macro using the Default Account

An IMAP user created this macro to open a new message form from any message store and use the default account as assigned in Account Settings.

To use: Go to File, Options, Customize Ribbon. Select Macros from Choose Commands from dropdown, add a New Group to Home tab then add the New Mail macro to the new group. Click the Rename button to rename the command and choose a better looking icon.

Text file containing both macros on this page.

Public Sub New_Mail()
Dim olNS As Outlook.NameSpace
Dim oMail As Outlook.MailItem

Set olNS = Application.GetNamespace("MAPI")
Set oMail = Application.CreateItem(olMailItem)

'use first account in list
    oMail.SendUsingAccount = olNS.Accounts.Item(1)
    oMail.Display
      
Set oMail = Nothing
Set olNS = Nothing

End Sub

See Using VBA Codeif you need help using VBA code.

Macro using a specific account

This macro is assigned to a button on the ribbon - clicking the button selects the account listed in the code. Replace Name_of_Default_Account with your account name (check in Account settings for the account name). You can create a macro for each account (change the Public Sub name) if desired.

Go to File, Options, Customize Ribbon. Select Macros from Choose Commands from dropdown, add a New Group to Home tab then add the New Mail macro to the new group. Click the Rename button to rename the command and choose a better looking icon.

If you need help customizing the ribbon, see Customizing the Quick Access Toolbar (QAT)

See Using VBA Code if you need help using VBA code.
Text file containing both macros on this page.

Public Sub New_Mail()
Dim oAccount As Outlook.Account
Dim oMail As Outlook.MailItem

For Each oAccount In Application.Session.Accounts
   If oAccount = "Name_of_Default_Account" Then
      Set oMail = Application.CreateItem(olMailItem)
      oMail.SendUsingAccount = oAccount
      oMail.Display
   End If
Next
End Sub

Note: this macro also works with Outlook 2007 (possibly older versions).

 

Set the From address on a message

Similar to the previous macro, except it uses a different From address, not a different email account in your profile. Because the message is sent from the default email account, the default account needs Send As permission for the address.

If the account does not have Send as permission, the message will be sent from the default account on behalf of the address or will bounce if using Exchange server. If you are using a SMTP server the message may be sent from the default account.

Use this code to fill in the From field with an address you have permission to send messages From.

Public Sub CreateNewMessageFrom()
Dim objMsg As MailItem

Set objMsg = Application.CreateItem(olMailItem)

 With objMsg
    .SentOnBehalfOfName = "alias@domain.com"
    .BCC = "alias2@domain.com"
    .Display
End With

Set objMsg = Nothing
End Sub

 

Send a meeting request using a specific account

Use this macro to send meeting requests using a specific account, irregardless of which data file you are viewing.

Public Sub NewMeeting()
Dim oAccount As Outlook.Account
Dim oMeeting As Outlook.AppointmentItem

For Each oAccount In Application.Session.Accounts

If oAccount = "account@displayname" Then
    Set oMeeting = Application.CreateItem(olAppointmentItem)
       oMeeting.MeetingStatus = Outlook.OlMeetingStatus.olMeeting
      oMeeting.SendUsingAccount = oAccount
    oMeeting.Display
End If
Next

End Sub

Using VBA Code

To use VBA code, press Alt+11 to open the VBA Editor. Locate ThisOutlookSession and paste the code into the editor.

Press F5 or the Run button to test the macro. (It's highly recommended you make a backup of the folder or message store before running macros.)

You'll also need to change macros security or use selfcert.exe to sign your macros. Access the dialog to change the security level from Tools, Macros, Security. (This is at File tab, Options, Trust Center, Macro Security in Outlook 2010). Set it on "always ask". Do not choose the Low option (run all, never ask). Some security software will set it to High and your macros will not run.

To run a macro later, press Alt+F8 to open the macro dialog, then select the macro and choose Run. Or add a button for the macro to your toolbar or add it to the QAT in Outlook 2010.

More Information

How to Enable the Developer Ribbon
See How to use VBA code samples in Outlook for more detailed information on using macros and selfcert.

Macros to send messages using a specific account was last modified: August 12th, 2020 by Diane Poremsky
  • Twitter
  • Facebook
  • LinkedIn
  • Reddit
  • Print

Related Posts:

  • Choose the account to send a reply from
  • Reply using the address a message was sent to
  • Use a macro to Reply with boilerplate text
  • Assign an Email Account to an Outlook Contact

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
51 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Arjan (@guest_219265)
May 5, 2022 10:36 am
#219265

Kudo's to you Diane !! Normally I get my "help" on stackoverflow but for my current job to automate sending an email from excel your articles and comments gave me all the help to do the job. thank u !!

0
0
Reply
John (@guest_218321)
June 1, 2021 3:44 pm
#218321

Hi Diane, is there a way we can specify the script to only run when e-mailing from a specific account. I have business and personal accounts in this case I would like the script only to send on behalf of when replying from my business account user@domain.com

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  John
June 1, 2021 5:31 pm
#218322

You can use an If statement to either skip or send

For Each oAccount In Application.Session.Accounts

If oAccount = "business@account" Then
'do whatever
End if

next

0
0
Reply
John (@guest_218325)
Reply to  Diane Poremsky
June 2, 2021 5:27 pm
#218325

Thank you for the response. As I do not have much experience with coding could you show me where in this code I would add the proper statements. Also would it be possible to put a universal variable such as if oAccount source is *@xyz.com then set sender address to delegate@domain.com:

Dim WithEvents objInspectors As Outlook.Inspectors
Dim WithEvents objMailItem As Outlook.MailItem
Dim WithEvents myOlExp As Outlook.Explorer

Private Sub Application_Startup()
  Initialize_handler
End Sub

Public Sub Initialize_handler()
  Set objInspectors = Application.Inspectors
  Set myOlExp = Application.ActiveExplorer
End Sub

Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
  If Inspector.CurrentItem.Class = olMail Then
    Set objMailItem = Inspector.CurrentItem
    If objMailItem.Sent = False Then
      Call SetFromAddress(objMailItem)
    End If
  End If
End Sub

'Uncomment the next 3 lines to enable Outlook 2013/2016/2019/365 Reading Pane Reply
'Private Sub myOlExp_InlineResponse(ByVal objItem As Object)
'  Call SetFromAddress(objItem)
'End Sub

Public Sub SetFromAddress(oMail As Outlook.MailItem)
  ' Set your preferred default From address below.
  ' Exchange permissions determine if it is actually stamped
  ' as "Sent On Behalf Of" or "Sent As".
  ' The address is not properly updated for the InlineResponse
  ' feature in Outlook 2013/2016/365. This is only a visual bug.
  oMail.SentOnBehalfOfName = "delegate@domain.com"
End Sub

Last edited 1 year ago by John
0
0
Reply
Josh (@guest_217824)
March 27, 2021 10:05 am
#217824

I have this code that I use with a ribbon button:

Sub FORWESP()
Dim objMail, objForward As Outlook.MailItem
Dim BodyIni, BodyEnd As String
Set objMail = Outlook.Application.ActiveExplorer.Selection.Item(1)
Set objForward = objMail.Forward
BodyIni = objForward.Body
BodyEnd = "Dear Xxxx," & vbCrLf & vbCrLf & "blabliblabli blabli" & vbCrLf & vbCrLf & "Sincerely" & vbCrLf & BodyIni   
With objForward
.Display
.Subject = "FW: " & objMail.Attachments.Item(1).FileName
.Body = BodyEnd
End With
End Sub

and now i want to also use a specific outlook account to send the email and I took this code from this page:

Public Sub New_Mail()
Dim oAccount As Outlook.Account
Dim oMail As Outlook.MailItem
For Each oAccount In Application.Session.Accounts
  If oAccount = "x@xxx.com" Then
   Set oMail = Application.CreateItem(olMailItem)
   oMail.SendUsingAccount = oAccount
   oMail.Display
  End If
Next
End Sub

But I am not smart enough to combine the two. Must be easy for someone who actually understands code... Would be great if someone could help...
Many Thanks
Josh

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Josh
April 29, 2021 5:02 pm
#218058

This works here -

Sub FORWESP()
Dim objMail, objForward As Outlook.MailItem
Dim BodyIni, BodyEnd As String
Dim oAccount As Outlook.Account

For Each oAccount In Application.Session.Accounts
 If oAccount = "dianep@outlook-marketplace.com" Then
 Set objMail = Outlook.Application.ActiveExplorer.Selection.Item(1)
Set objForward = objMail.Forward

  objForward.SendUsingAccount = oAccount
End If
Next

BodyIni = objForward.Body
BodyEnd = "Dear Xxxx," & vbCrLf & vbCrLf & "blabliblabli blabli" & vbCrLf & vbCrLf & "Sincerely" & vbCrLf & BodyIni
With objForward
.Display
.Subject = "FW: " & objMail.Attachments.Item(1).FileName
.Body = BodyEnd
End With
End Sub

0
0
Reply
yvonne Chavez (@guest_217276)
December 8, 2020 5:08 pm
#217276

Hi Diane: can you tell me why some vba scripts "MakeItem" in their code and others use "msg.display" to view email templates.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  yvonne Chavez
April 29, 2021 4:56 pm
#218057

Mailitem is used when you are opening a new message, .display displays the message.

0
0
Reply
michelle mason (@guest_216013)
October 6, 2020 5:05 pm
#216013

Hi. RE: Macro for prepopulating a Subject within a current email (not a new one) How do I get the macro to process within the email I am currently in instead of it populating a new one email altogether as soon as I engage the macro? I use a system client database called Applied EPIC and it works with outlook. I click on my client's email address within that database and it activates an outlook email window (EPIC is connected to Outlook). I hit ALT N→ AS to drop a prepopulated signature and then ALT N→Y to engage a macro (which I built to prepopulate the subject). I already tried Quick Steps, and it is the same (only starts a new email when i want it to use the one I am in). Here is the Macro Sub New_Secure_Email() Dim MItem As MailItem Set MItem = Application.CreateItem(olMailItem) MItem.subject = "friendly reminder; renewal 10/9/20" MItem.Display End Sub Can i recode the macro so that it will work within the email i am in? When i use this one it pops up a *new email* which i cannot use because i need to use the one that happened in the beginning (because… Read more »

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  michelle mason
October 7, 2020 12:48 am
#216018

This line calls for a new message:
Set MItem = Application.CreateItem(olMailItem)

You need to use activeinspector
Set MItem = Application.ActiveInspector.CurrentItem

0
0
Reply
michelle mason (@guest_216049)
Reply to  Diane Poremsky
October 13, 2020 12:06 pm
#216049

Thanks... that makes sense. HOWEVER, now i get an error message "The macros in this project are disabled. Please refer to the online help or documentation of the host application to determine how to enable macros." I wasn't getting this message before. It worked (albeit, creating a new one.). Thoughts?

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  michelle mason
October 13, 2020 12:55 pm
#216050

Are macros enabled in file > options > trust center > macro security?

0
0
Reply
michelle mason (@guest_216052)
Reply to  Diane Poremsky
October 13, 2020 1:28 pm
#216052

nevermind. I had changed back the set mltem by mistake and now using the one you suggested. IT's WORKING NOW.

Sub New_Secure_Email()
Dim MItem As MailItem
Set MItem = Application.ActiveInspector.CurrentItem
MItem.subject = "friendly reminder; renewal 10/12/20"
MItem.Display
End Sub

0
0
Reply
Sam (@guest_214977)
March 30, 2020 3:21 pm
#214977

Hi,
Some great stuff and pretty easy to follow . But I#m not sure I can make the next leap :-(

As part of a mail rule script I would like to forward an email having inserted some text and a picture (in line not as an attachment) before the email that triggered the rule (so just like a normal forwarding process.)

How can I do this with VBA?

TFAI

0
0
Reply
Matt (@guest_212799)
February 17, 2019 8:06 pm
#212799

Hello,

Could anyone direct a novice office user to assist in the following, I think it would be simple and functionality exist.

What I am trying to do is the following:

1) Report a Suspicious Email
2) On a email that has arrived I would like to set a button or method to
a) On selected email, forward to a mail box and then delete the original email.
b) Prefer to attach original email for header inspection.

Based on this we can review the original suspicious email and review prior to sending back to user. More for Phishing response due to amount of volume.

Basically I can view a inbox with suspicious email for review, with original attachment can inspect headers and URL in sandbox environment for inspection.

Dont expect it to be unique requirement so possibly a Macro or VSB script exists.

Can I use powershell as more experience on this tool than VBA ?

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Matt
October 27, 2019 11:26 pm
#214181

A macro can do it, not sure about powershell. i have this sample for spam reports - it includes the message header in the forward body.
https://www.slipstick.com/developer/code-samples/outlooks-internet-headers/#spam

0
0
Reply
David Boyd (@guest_211881)
September 6, 2018 6:42 am
#211881

Wow, why is this so hard? What I need is to make sure that Mailmerge from Word uses my default account (gmail) rather than my hotmail account.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  David Boyd
September 6, 2018 8:53 am
#211883

gmail is default for email and Hotmail is the default data file? The non-macro method is to make second profile with only the gmail account.

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 28 Issue 11

Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Subscribe to Exchange Messaging Outlook






Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • WeekMonthAll
  • Adjusting Outlook's Zoom Setting in Email
  • How to Remove the Primary Account from Outlook
  • Cannot add Recipients in To, CC, BCC fields on MacOS
  • Move an Outlook Personal Folders .pst File
  • Save Sent Items in Shared Mailbox Sent Items folder
  • Create rules that apply to an entire domain
  • Outlook's Left Navigation Bar
  • Use PowerShell to get a list of Distribution Group members
  • View Shared Calendar Category Colors
  • Remove a password from an Outlook *.pst File
  • Cannot add Recipients in To, CC, BCC fields on MacOS
  • Change Appointment Reminder Sounds
  • Messages appear duplicated in message list
  • Reset the New Outlook Profile
  • Delete Old Calendar Events using VBA
  • Use PowerShell or VBA to get Outlook folder creation date
  • Outlook's Left Navigation Bar
  • Contact's Display Bug
  • Use PowerShell to get a list of Distribution Group members
  • Edit Outlook’s Attach File list
Ajax spinner

Newest Code Samples

Delete Old Calendar Events using VBA

Use PowerShell or VBA to get Outlook folder creation date

Rename Outlook Attachments

Format Images in Outlook Email

Set Outlook Online or Offline using VBScript or PowerShell

List snoozed reminders and snooze-times

Search your Contacts using PowerShell

Filter mail when you are not the only recipient

Add Contact Information to a Task

Process Mail that was Auto Forwarded by a Rule

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in Outlook for Windows.

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




Windows 10 Issues

  • iCloud, Outlook 2016, and Windows 10
  • Outlook Links Won’t Open In Windows 10
  • Outlook can’t send mail in Windows 10: error Ox800CCC13
  • Missing Outlook data files after upgrading Windows?

Outlook Top Issues

  • The Windows Store Outlook App
  • The Signature or Stationery and Fonts button doesn’t work
  • Outlook’s New Account Setup Wizard
  • Outlook 2016: No BCM
  • Exchange Account Set-up Missing in Outlook 2016

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

Outlook-tips.net Samples

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

MSDN Outlook Dev Forum

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Contact Tools

Data Entry and Updating

Duplicate Checkers

Phone Number Updates

Contact Management Tools

Diane Poremsky [Outlook MVP]

Make a donation

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Outlook Suggestion Box (UserVoice)

Slipstick Support Services

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Advertise | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2023 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment