Solved

Avoiding insertion of a redundant suffix to recipient's Email

Posted on 2014-02-26
2
372 Views
Last Modified: 2014-02-26
Running Outlook 2007, an Expert has assisted me in coding a script which appends a suffix to the recipient's Email address.  For details, please see http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_28374041.html

This works just as I had hoped, but there is a small, unexpected issue.  I have Outlook configured to suspend "sent" messages in the Outbox until a second instance of Send/Receive is executed.  Sometimes I need to review an outbound message, before sending it, and this approach allows me to do that.  If I open a message in the Outbox, make any changes, and then send it, the script appends a second suffix to the recipient's Email address.  If I'm paying attention, of course I will delete the redundant suffix.  However, if there's an easy way to adjust the script so that another suffix won't be added, I'd like to know.
0
Comment
Question by:ddantes
2 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 39889895
That's simple enough.  This should do it.  Replace the code you have now with this version.

Dim bolAddSuffix As Boolean

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim olkRcp As Outlook.RECIPIENT, olkNew As Outlook.RECIPIENT, intCnt As Integer
    If bolAddSuffix Then
        If Item.Class = olMail Then
            For intCnt = Item.Recipients.Count To 1 Step -1
                Set olkRcp = Item.Recipients.Item(intCnt)
                olkRcp.Resolve
                If InStr(1, LCase(olkRcp.Address), "whoreadme.com") = 0 Then
                    Set olkNew = Session.CreateRecipient(olkRcp.Address & ".whoreadme.com")
                    olkNew.Resolve
                    olkRcp.Delete
                    Item.Recipients.Add olkNew
                End If
            Next
            Item.Recipients.ResolveAll
            Item.Save
        End If
    End If
End Sub

Sub ToggleAddSuffix()
    bolAddSuffix = Not bolAddSuffix
    MsgBox "AddSuffix is now " & IIf(bolAddSuffix, "ON", "OFF"), vbInformation + vbOKOnly, "Toggle Add Suffix"
End Sub

Open in new window

0
 

Author Comment

by:ddantes
ID: 39889941
Perfect.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

932 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

9 Experts available now in Live!

Get 1:1 Help Now