Alert when sending from the non-default email account?

MikeToTheP 1 Reputation point
2021-02-19T22:39:27.663+00:00

I manage several email addresses through Outlook and I'm looking for a way to alert me whenever I'm sending and my FROM address is any account other than the default account. Every now and then I just don't realize that I have one of the other email Inboxes selected and when I click "New Email", it defaults to sending from that particular account. Actually, Ideally, I'd love to be able to put a color border around the whole email that corresponds to which account it's from, but I suspect that would be harder than a warning before sending. So basically, what I want is ANY time I'm sending FROM any account other than the default account, I want it to pop up and say "Are you sure?" I think that will be enough to prevent me from accidentally sending FROM the wrong email. I looked into the "on-send" programming and I'll pursue that if I can't find anything that already exists, just thought I'd check to see if someone has already done something similar?

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,656 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vahid Ghafarpour 20,030 Reputation points
    2023-08-01T18:48:46.2966667+00:00

    You can create a macro using VBA to handle your request, something like the following example:

    Option Explicit
    
    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
        Dim olApp As Outlook.Application
        Dim olNamespace As Outlook.NameSpace
        Dim olAccounts As Outlook.Accounts
        Dim olAccount As Outlook.Account
    
        Set olApp = Outlook.Application
        Set olNamespace = olApp.GetNamespace("MAPI")
        Set olAccounts = olNamespace.Accounts
    
        ' Assuming 1st account in the list is the default account
        Set olAccount = olAccounts.Item(1)
    
        ' Check if the From email address is different from the default account
        If Item.SentOnBehalfOfName <> olAccount.SmtpAddress Then
            Dim response As VbMsgBoxResult
            response = MsgBox("Are you sure you want to send this email from a non-default account?", vbYesNo + vbExclamation + vbDefaultButton2, "Warning")
            If response = vbNo Then
                Cancel = True
            End If
        End If
    
        ' Release objects
        Set olAccount = Nothing
        Set olAccounts = Nothing
        Set olNamespace = Nothing
        Set olApp = Nothing
    End Sub
    
    
    0 comments No comments