Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to warn before sending emails with multiple domains #15

Open
huvanile opened this issue Oct 28, 2016 · 0 comments
Open

Option to warn before sending emails with multiple domains #15

huvanile opened this issue Oct 28, 2016 · 0 comments

Comments

@huvanile
Copy link
Owner

This could be achieved through a toggle button on the ribbon which would execute this code if checked:

Private Sub mailCheck_Send(item As Object, Cancel As Boolean)
'Purpose: if recipients cover more than one domain, confirm before sending
'Reason for existence: Warn user before sending if email is addressed to more than one client, probably accidentally

    Dim part As Variant
    Dim confirm As Boolean
    Dim recs As String
    Dim prompt As String
    Dim domain As String
    Dim r As Recipient
    Dim myNewMail As MailItem

    On Error GoTo oops
    Set myNewMail = item

    If myNewMail Is Nothing Then Exit Sub

    confirm = False
    recs = ""

    'determine domains of recipients
    For Each r In myNewMail.Recipients
        Debug.Print r.Name; ","; r.Address
        part = Split(r.Address, "@", 2)
        If UBound(part) > 0 Then 'external address
            domain = part(1)
            If Not domain Like "*.gt.com" Then
                'compare domains
                If recs <> "" And InStr(recs, domain) = 0 Then confirm = True
                recs = recs & ", " & domain
            End If
        Else 'internal address, do nothing
        End If

    Next

    'prepare msg prompt
    prompt = "Are you sure you want to send this message?"
    If confirm Then
        recs = Mid(recs, 2)
        prompt = Replace(prompt, "?", " to outside domains: " & recs & "?")
    End If

    'ask user.  Comment "if" statement if you want to ask all the time
    If confirm Then
        If MsgBox(prompt, vbYesNo + vbQuestion + vbDefaultButton2, "SEND CONFIRMATION") = vbNo Then
            Cancel = True
        End If
    End If
    Exit Sub
oops:
    MsgBox Err & " " & Err.Description, vbCritical
    Set myNewMail = Nothing
End Sub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant