Solved

auto select sender account in Outlook for 2 SMTP account

Posted on 2011-02-20
13
1,497 Views
Last Modified: 2013-12-18
Hi Expert,
              Our office has internal mail server. I have 2 smtp acount setup in Outlook. 1 is for internal mail server and another one is for external mail server. I would like outlook to auto select the sender account according to the recipients. If the recipient is non external user, I want outlook to select internal mail server sender account automatically when I reply or forward message.
For non internal recipients, I want outlook to select the external email server account automatically when reply or forward message.
And I want to restrict the internal account to sending out to non-internal recipients.
Is there anyway to program by VB in Outlook ?
I appreciate your soonest reply.
Thanks
0
Comment
Question by:bominthu
  • 6
  • 6
13 Comments
 
LVL 41

Expert Comment

by:Amit
ID: 34938155
Sounds interesting but not possible.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 34938801
Hi, bominthu.

This is possible with a script.  What version of Outlook are you using?
0
 
LVL 4

Author Comment

by:bominthu
ID: 34939778
Hi BlueDevilFan.
                    I have outlook 2003 , 2007 and 2010 users.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 34939946
I want to make sure i have rules correct.  Please confirm that these are the right conditions.

1.  If all recipients are internal, send through the the internal account.
2.  If all recipients are external, send through the external account.
3.  If there are a mix of internal and external recipients, which account should the code send through?
0
 
LVL 4

Author Comment

by:bominthu
ID: 34940020
it is mix of internal and external recipients. What we want is when the user reply or forward the message, I want outlook to auto select the sender account according to the recipients.
Like when we reply, it should open 2 outlook reply message ( 1 for internal and another one for External)

we would like to restrict internal users to sending out to external users as well.

0
 
LVL 76

Expert Comment

by:David Lee
ID: 34940138
"Like when we reply, it should open 2 outlook reply message ( 1 for internal and another one for External)"

Oh.  That wasn't clear at all.    I though you wanted to have Outlook automatically choose the sending account based on whether the recipients were internal or external.  I didn't realize you wanted to split them out.  It's still doable, but definitely more complicated.

----

"we would like to restrict internal users to sending out to external users as well."

Hmmm.  Why would you want to split messages into internal senders and external senders if you want to prohibit sending to external senders?  I must be missing something.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 4

Author Comment

by:bominthu
ID: 34940235
the main thing is how can we let Outlook to select the sender account automatically when they reply for forward, the recipients are mixed internal users and external users ?
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 34940396
Ok.  This should do it for Outlook 2003 and 2007.  I don't have a computer with 2010 available at the moment, so I'm not sure it will work in that version.  Follow these instructions to add the code to Outlook 2003 and 2007

Outlook 2003.

1.  Start Outlook
2.  Click Tools > Macro > Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of
5.  Outlook's VB Editor window
6.  Edit the code as needed.  I included comment lines wherever something needs to or can change
7.  Click the diskette icon on the toolbar to save the changes
8.  Close the VB Editor
9.  Click Tools > Macro > Security
10. Set the Security Level to Medium
11. Close Outlook
12. Start Outlook
13. Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run.  Say yes.


Outlook 2007

1.  Start Outlook
2.  Click Tools > Macro > Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
5.  Edit the code as needed.  I included comment lines wherever something needs to or can change
6.  Click the diskette icon on the toolbar to save the changes
7.  Close the VB Editor
8.  Click Tools > Trust Center
9.  Click Macro Security
10. Set Macro Security to "Warnings for all macros"
11. Click OK
12. Close Outlook
13. Start Outlook.  Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run.  Say yes.

The code works by checking messages as they are sent.  If the item being sent is an email, then the code loops through the addressees and counts the number that are internal and external.  It then checks those counts to decide what to do next.  If all the recipients are internal, then it sends through the internal account.  If all the recipients are external, then it sends through the external account.  If there is a mix, then at the moment it does nothing.  I left a placeholder for splitting the message into two messages: one for the internal recipients and another for the external ones.

If you only want this to work for forwards and replies and not new messages, then I'll need to add one additional test.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    'On the next line edit the name of your domain.  Enter it in lowercase.'
    Const MY_DOMAIN = "@company.com"
    'On the next line enter the ordinal number of the internal account as it appears in the lsit of accounts.'
    Const INT_ACCOUNT = 1
    'On the next line enter the ordinal number of the external account as it appears in the lsit of accounts.'
    Const EXT_ACCOUNT = 2
    Dim olkRcp As Outlook.Recipient, intExternal As Integer, intInternal As Integer, ofcPopup As Object, ofcBtn As Object
    If Item.Class = olMail Then
        Set ofcPopup = Application.ActiveInspector.CommandBars("Standard").Controls(3)
        For Each olkRcp In Item.Recipients
            If InStr(1, LCase(olkRcp.Address), MY_DOMAIN) Then
                intInternal = intInternal + 1
            Else
                intExternal = intExternal + 1
            End If
        Next
        If intInternal > 0 And intExternal = 0 Then
            Set ofcBtn = olkSendThroughBtn.Controls(INT_ACCOUNT)
            ofcBtn.Execute
        Else
            If intInternal = 0 And intExternal > 0 Then
                Set ofcBtn = olkSendThroughBtn.Controls(EXT_ACCOUNT)
                ofcBtn.Execute
            Else
                'This is where the code would go that splits the message into two messages for those messags that have a mix of internal and external accounts.'
            End If
        End If
    End If
    Set olkRcp = Nothing
End Sub

Open in new window

0
 
LVL 4

Author Comment

by:bominthu
ID: 34940444
For example my internal account is abc@internal.com and external account is def@external.com.
 I have only 1 internal and 1 external account.
Which portion i should substitute in above VB code for my abc@internal.com and def@external.com?

Could you include the code for new message as well ?

Thanks
0
 
LVL 4

Author Comment

by:bominthu
ID: 34944657
Hi BlueDevilFan,
        Any update ?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 34956743
On line #3 change "@company.com" to "@internal.com".  The code already handles new messages.  I'd have to change it if you wanted it to only handle replies and forwards.
0
 
LVL 4

Author Comment

by:bominthu
ID: 35121229
Could you make the script for replies and forwards as well ?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 35142390
Right now it handles any message you send.  Are you saying that you want it to handle replies and forwards only and not new messages?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
exchange, outlook 6 31
outlook 2013 8 30
IMAP folders 4 35
RELIABLE Family Calendar solution for Exchange/Outlook + iPhones 3 17
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now