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.
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 ?
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.
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.
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.
Hi,
Basically my first time using VBA and have been all over youtube watching videos trying to learn. I have run into the issue of only being able to send the email when I run the macro. How can I get it to send every time I click on the command?
these samples are all manual options. the macros at https://www.slipstick.com/developer/code-samples/default-subject-messages/ show how to do something when the compose message form opens. You'd use this - m_Inspector.SendUsingAccount = olNS.Accounts.Item(1) - to set the account.
if you want every new message to be sent from the default account and use 2010, 2013 or 2016, there is an registry key always use the default account. See https://www.slipstick.com/outlook/outlook-2010/multiple-accounts-and-the-default-account/#sp1 for details.
Hi,
I'm not a VBA coder by any means and I tried this a few ways, but I'm running into an issue.
I tried to combine the code in this post with a another piece of code I have.
Cut to the chase: I have an oft file with formatting, and a signature line with a graphic and it looks great, but it keeps putting my default FROM field (I need it to use an e-mail address I have "SEND ON BEHALF" access to.
Is there some way to combine the code in this post with the following code, or is there a way in VBA to put in all my fancy-schmancy formatting?
Before .display, you need to set the sendonbehalfof address -
Sub DoIt()
Set msg = [snipped]
msg.SentOnBehalfOfName = "sales@domain.com"
msg.Display
End Sub
if it's another account in your profile (listed in File, Account settings), you need to do it slightly differently - use
msg.SendUsingAccount = olNS.Accounts.Item(2) ' where 2 is the second account in the accounts list
(put these two lines at the top of the macro -
Dim olNS As Outlook.NameSpace
Set olNS = Application.GetNamespace("MAPI"))
Hey everyone, I have created a macro to send template emails using a button on the ribbon, I can't seem to figure out how to add a send on behalf function to my macro template. Admittedly I have very little training in VBA, all I can really do is take templates and try to wiggle them into my needs. Here is an example of my macro, how do I add in the "sendonbehalfofname" functionality?
Dim Template As String
Sub OpenTemplate1Thankyou
Template = "J:Thank you.oft"
MakeItem
End Sub
You'd use this in the makeitem macro - it needs to be set before you display the message.
newItem.SentOnBehalfOfName = "alias@domain.com"
So my question is, can I set a rule up that whenever a specific account receives an email with an attachment from a certain person it will download it to my chosen Directory on my computer?
I have a Macro that will look in to the email object and grab the attachment and download it. Kind of look like this...
Public Sub saveAttachtoDisk(itm As MailItem)
Dim objAtt As Outlook.Attachment
MsgBox "LRA1, LRA2, and Analyst1 have been updated"
Dim saveFolder As String
saveFolder = "M:RLB Customer ExperienceLRA_FileStorage"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "" & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub
The thing is that I have two accounts set up and I want to make sure that it only works with one of the Outlook accounts.
You can create rules specific to one account - one of the conditions is received on account but if they are imap or exchange, they will have their own separate rules.
With the following code I have to try to block an account.
But when I save the mail -> close Outlook -> open Outlook -> Try to send the saved mail it comes to an error but I see no error message.
use this to set the account
Dim oAccount As Outlook.Account
For Each oAccount In Application.Session.Accounts
If oAccount = "xxx@xxx.com" Then
msgbox "....
I have been trying to get the .SentOnBehalfOfName function to work consistently. I have developed an outlook custom process that is distributed across multiple users that needs to send a receipt message to the sender once processing of their attachments is completed. The code scans a shared mailbox and the receipt message needs to come from the shared mailbox address The code I have written works inconsistently. It works when the code is processed on my PC and when processed on one other individual. For 2 other individuals, the code works appropriately until the step where the receipt message is generated and sent **PLEASE NOTE** all individuals have been setup as delegates with appropriate permissions to send on behalf of the mailbox - I have visually watched the mailbox owner configure each of these individuals. The code executes a send command but the exchange server sends back an error email which is attached but modified to exclude mailbox names, email addresses etc. This is my code: With olMsg .Attachments.Add Item, olEmbeddeditem .Subject = "**ATTENTION PURCHASING TEAM: New Supplier Item Update Form(s) have been received for CMS Processing " & (Now) .To = "someone@hotmail.com" .CC = "" .BCC = "" .Body… Read more »
Does the NDR give you any clues? Does the other person who it works for also have send as permissions to your mailbox? I'm thinking it's not using the person's account and is trying to use your account.