Reply using the address a message was sent to

Last reviewed on April 1, 2014

Use this code to send a new message using the address the selected message was sent To as the send using From account.

This code is for people who use an account such as Gmail or Hotmail to collect mail from other accounts and download only that account. Outlook will always reply using the account that downloaded the message, which is the Hotmail or Gmail account. You'll need to create an account in Outlook for the other addresses to use this code, but can set the accounts to never download email.

This code gets the address the message was sent to and looks for an existing account with the same display name and uses that account. If it can't find a matching account it uses the default account.

Update: I fixed the macro, it now checks for a specific string (an email address) in the To field. If it finds the address, the reply is from that address, otherwise the reply is from the default address. If you need to check for one of several accounts, you'll need to use an array.

To force the code to always use a specific non-default account, change this line:
objMsg.SendUsingAccount = olNS.Accounts.Item(1) to
objMsg.SendUsingAccount = olNS.Accounts.Item(2) where 2 is the placement of the account in the Account Settings list
or objMsg.SendUsingAccount = "Display name of desired account"

If you are using Exchange server and have Send as permission to the address a message was sent to (such as a distribution list), replace the For Each... Next block with:
objMsg.MailItem.Sender = oMail.To
or
objMsg.SentOnBehalfOfName = oMail.To

This may not work with Outlook 2013's "inline replies". Messages will be opened in a new Window.

Reply from the address a message was sent to

Public Sub AccountSelection()
Dim oAccount As Outlook.Account
Dim strAccount As String
Dim objMsg As MailItem, oMail As MailItem
Dim olNS As Outlook.NameSpace     

Set olNS = Application.GetNamespace("MAPI") 

' For a reply all version, replace Reply with ReplyAll 
Set objMsg = ActiveExplorer.Selection.Item(1).Reply

If TypeName(ActiveExplorer.Selection.Item(1)) = "MailItem" Then
 Set oMail = ActiveExplorer.Selection.Item(1)
 
 On Error Resume Next

For Each Recipient In oMail.Recipients
 strRecip = Recipient.Address & ";"& strRecip
Next Recipient


If InStr(strRecip, "alias@domain1.com") > 0 Then
' StrAccount is the account name as shown in the Account Settings list
strAccount = "alias@domain1.com"
Else
End If
 
 For Each oAccount In Application.Session.Accounts
  If oAccount.DisplayName = strAccount Then
     objMsg.SendUsingAccount = oAccount
       Else

     ' to reply using the account that downloaded the message
     ' leave the objMsg line commented
     ' remove comment to reply using default account
     ' objMsg.SendUsingAccount = olNS.Accounts.Item(1)

  End If
Next
  objMsg.Display
Else

End If

Set objMsg = Nothing
End Sub

How to use macros

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.
  3. Click Run to test the macro

When you're happy with the macro, create a ribbon or QAT button for the macro.

More information as well as screenshots are at How to use the VBA Editor

Written by

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.

Please post long or more complicated questions at Outlookforums.

24 responses to “Reply using the address a message was sent to”

  1. Peauxboy

    This is EXACTLY what I am looking for!!! I think. I'd like to use this so that customer service representatives always respond with my companies support email when responding to messages in a specific public folder instead of their own without requiring them to remember to change the From field. My only problem is how do I implement this? In other words, what do I need to do so that this is used?

    Thanks so much!

  2. Derik du Plessis

    This is great as it is exactly what i needed. I also modified the macro to include a forward version. However the macros does not run when i press the Reply, Reply All or Forward buttons either on the ribbon or the "inline" buttons they do run successfully when i execute them from the developer pane or the macro pane. How can i get them to run automatically?

    Once again, thanks for this great macro!!

  3. Derik du Plessis

    As i do not like answering email or creating new ones in the actual reading pane, i changed the setting in options/mail/replies and forwards to always open in a new window (first check box) and now the macros run automatically and i am always presented with the correct mail account to use when answering emails. This works for both the ribbon as well as inline "Reply", "Reply All" and "Forward" buttons. Please do not ask me why, as MS is sometimes a black art.

    Any idea how i can get the same funcionality when creating a new meeting invitation?

  4. Derik du Plessis

    Diane, i have just experiment more, the above indicated actually has nothing to do with the macros, instead by changing the option indicated this affected an add in that i have called SAM, and that activates the correct sending account. Sorry about the confusion.

    Regards

  5. Ascar Omarov

    Derik, may I ask you to share the modified code which includes the Forward function? Did you try to make the Reply All and Forward as Attachment functions to work as well?

  6. Fabio Quintal

    I know this is an old post but I wanted to thank Diane for posting this macro.

    Diane:

    This worked perfectly for me, I tend to read most of my mail on the default reading pane (as opposed to opening the email completely -which doesn't work). I actually created three different Macros for REPLY, REPLY ALL, and FORWARD and replaced the buttons on the ribbon so I wouldn't click them by mistake. The only change (besides the obvious changes) I added a line "strRecip = LCase(strRecip)" because I noticed the Macro would not work correctly if the person used uppercase when typing the email address...for example if they typed it as info@mydomain.com it would work fine but if they typed it as Info@mydomain.com or INFO@mydomain.com or even the domain itself it would NOT work. With this addition everything works!

    Ascar Omarov:

    In case you're still looking for the Forward...just replace the line:

    Set objMsg = ActiveExplorer.Selection.Item(1).Reply

    with

    Set objMsg = ActiveExplorer.Selection.Item(1).Forward

    And everything should work for forwarding.

  7. Michael

    Are you using Office 2013? I just can't seem to make it work no matter what I do!

  8. Michael

    Thanks so much!!! If there is anything I can do to provide data I will -- just shoot me an email and I can send screenshots or anything.

  9. Michael

    Did you retest? I have now tried on three different computers with the most recent Outlook 2013 with all updates on Windows 8.1. None of them are working.

  10. Michael

    That fixed it!!! Thanks so much

  11. Michael

    Diane, Found one more weird thing. If the email is sent to me ONLY (example To: a@b.com) the macro works.

    However, if it is To: a@b.com; differentemail@c.com then it does not work. As in, if my email is only one of multiple addresses it does not work.

    What would I need to modify to say if my email address is anywhere in the To: field then apply this rule?

  12. Fabio

    To expand on this Macro, I wanted to include a specific Category every time I send from this Macro but I can't seem to do it. I thought it was simple as:

    .Category = "Sent from Reply Macro"

    Obviously the Category has already been created. I saw a few examples where a macro can display a list of categories to choose from but I can't seem to just set one without having to choose.

    I'm not an expert on vb, so that might be the problem ;-)

    -Fabio

  13. Fabio

    Duh!...thanks Diane...I'd probably still be typing ".Category"...for those of you who want to know. I added the following to this macro.

    ' Set Category
    objMsg.Categories = "Sent By Fabio"
    objMsg.Save

    The reason I did it was due to the fact that my company is using Google Apps and because I'm using outlook in my office PC and my laptop, I have to use the "recent:" setting (recent:fabio@mydomain.com) on both machines, so I can make sure I get emails in both machines. Google mail seems to ignore the POP setting to leave messages on the server so it can be retrieved by another machine and IMAP doesn't work too well. The problem is that you get a duplicate of every email you sent into your inbox and when you're responding to lots of emails from clients (along with other co-workers using the same email aliases --- we really need a ticketing system but the boss thinks it's unnecessary). Anyway, I needed to identify the messages I sent versus the messages my co-workers sent, so I couldn't filter via the incoming email address otherwise I might miss one of their responses. So assigning a category only to the messages I sent allows one of my rules to delete incoming messages with this category, after all I already have a copy of the message I sent in my sent items folder -- I don't need another copy!

    Now if, I could auto assign a category every time I click a NEW email so my rule would work for my own messages (not using one of the aliases) everything would be perfect. Still, I can at least filter messages coming from my own email in a separate rule, so it's not so bad.

  14. Fabio

    Ok... Now you got me, what's an inspector?

Leave a Reply

If the Post Coment button disappears, press your Tab key.