Parandaloni me kusht Outlook nga dërgimi i emaileve bazuar në adresat nga dhe marrësit

Unë kam konfigurim të shumë llogarive të postës në Outlook 2007 (p.sh., [email protected], [email protected], etj.). Herë pas here, zakonisht si rezultat i funksionit Auto Complete, gabimisht do t'i dërgoj email nga [email protected] një marrësi që duhet të marrë postë vetëm nga [email protected]).

Këto kufizime midis adresave të emailit nga (llogaria ime e zgjedhur e postës) ​​dhe marrësi (Për ose CC) mund të përcaktohen përgjithësisht nga emri i domenit.

Për shembull, [email protected] nuk duhet të dërgojë te recipient-domainX.com & recipient-domainY.com. Dhe [email protected] nuk duhet të dërgojë te recipient-domain1.com & recipient-domain2.com.

Pra, do të ishte mirë që në mënyrë eksplicite të përcaktohen ose "kodohen të forta" këto kufizime të domenit për llogari të postës në një skript VBA ose skedar teksti.

Pra, si, duke përdorur VBA ose mjete të tjera, mund të zbatoj një kontroll të adresave të emailit, për të parandaluar dërgimin e një emaili nëse shkelet një nga këto kufizime.

E hapur edhe për zgjidhje të tjera më elegante.

Faleminderit.


person splounx    schedule 08.04.2011    source burimi


Përgjigjet (2)


Kjo ju lejon të kontrolloni emailet sipas adresës. Nuk mund të kërkoj shumë kredi për këtë, janë kryesisht disa kode të ndryshme të postuara në internet të bashkuar në një. Pavarësisht, funksionon mirë dhe duhet t'ju çojë në gjysmë të rrugës atje ku dëshironi të jeni. Kjo përdoret në kompaninë tonë për të dërguar të gjitha emailet e dërguara nga jashtë në një dosje publike të rishikimeve të burimeve njerëzore.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    If Item.Class <> olMail Then Exit Sub
    Dim objMail As MailItem
    Set objMail = Item
    Dim NotInternal As Boolean
    NotInternal = False
    Dim objRecip As Recipient
    Dim objTo As Object
    Dim str As String
    Dim res As Integer
    Dim strBcc As String
    On Error Resume Next
    Const PidTagSmtpAddress As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
    Dim i As Integer
    Dim objRecipColl As Recipients
    Set objRecipColl = objMail.Recipients
    Dim objOneRecip As Recipient
    Dim objProp As PropertyAccessor
    For i = 1 To objRecipColl.Count Step 1
        Set objOneRecip = objRecipColl.Item(i)
        Set objProp = objOneRecip.PropertyAccessor
        str = objProp.GetProperty(PidTagSmtpAddress)
        If Len(str) >= 17 Then  'Len of email address screened.  
            If UCase(Right(str, 17)) <> "@COMPANYEMAIL.COM" Then NotInternal = True
        Else
            NotInternal = True
        End If
    Next
    If NotInternal = True Then
        strBcc = "[email protected]"
        Set objRecip = objMail.Recipients.Add(strBcc)
        objRecip.Type = olBCC
            If Not objRecip.Resolve Then
                strMsg = "Could not resolve the Bcc recipient. " & _
                         "Do you still want to send the message?"
                res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
                        "Could Not Resolve Bcc Recipient")
                If res = vbNo Then
                    Cancel = True
                End If
            End If
    End If
    Set objRecipColl = Nothing
    Set objRecip = Nothing
    Set objOneRecip = Nothing
    Set objMail = Nothing
    Set objTo = Nothing
    Set oPA = Nothing
End Sub
person Ken    schedule 22.07.2011

E kam modifikuar kodin që të jetë pak më i lehtë për t'u lexuar, efektivisht i njëjti kod pak më i pastër.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

If Item.Class <> olMail Then Exit Sub

Dim sCompanyDomain As String: sCompanyDomain = "companydomain.com"

Const PidTagSmtpAddress As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"

On Error Resume Next
Dim oMail As MailItem: Set oMail = Item
Dim oRecipients As Recipients: Set oRecipients = oMail.Recipients
Dim bDisplayMsgBox As Boolean: bDisplayMsgBox = False

Dim sExternalAddresses As String
Dim oRecipient As Recipient

For Each oRecipient In oRecipients

    Dim oProperties As PropertyAccessor: Set oProperties = oRecipient.PropertyAccessor
    Dim smtpAddress As String: smtpAddress = oProperties.GetProperty(PidTagSmtpAddress)

    Debug.Print smtpAddress

    If (Len(smtpAddress) >= Len(sCompanyDomain)) Then

        If (Right(LCase(smtpAddress), Len(sCompanyDomain)) <> sCompanyDomain) Then

            ' external address found
            If (sExternalAddresses = "") Then

                sExternalAddresses = smtpAddress

            Else

                sExternalAddresses = sExternalAddresses & ", " & smtpAddress

            End If

            bDisplayMsgBox = True

        End If

    End If

Next

If (bDisplayMsgBox) Then

    Dim iAnswer As Integer
    iAnswer = MsgBox("You are about to send this email externally to " & sExternalAddresses & vbCr & vbCr & "Do you want to continue?", vbExclamation + vbYesNo, "External Email Check")

    If (iAnswer = vbNo) Then
        Cancel = True
    End If

End If

End Sub
person Abu Belal    schedule 12.07.2013