Solved

Macro not working properly.

Posted on 2008-10-16
16
959 Views
Last Modified: 2012-05-05
I had a macro written by BlueDevilsFan that appends a string to the end of any email address that I am sending to. It worked great. However, I have found a glitch that has turned out to be very serious. Whenever I send to BCC contacts, and the string is added to those addresses in the BCC field, the addresses are somehow moved into the TO: field after hitting send. I need to know if this can be fixed or else I cant use it. The blind ccs need to stay blind or else it defeats the purpose. Any help would be greatly appreciated.

Here is the macro:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim olkRecipient As Outlook.Recipient, _
        olkNewRecipient As Outlook.Recipient, _
        strAddress As String, _
        intIndex As Integer
    If Item.Class = olMail Then
        For intIndex = Item.Recipients.Count To 1 Step -1
            Set olkRecipient = Item.Recipients(intIndex)
            If InStr(1, olkRecipient.Address, "@") Then
                If Not (InStr(1, LCase(olkRecipient.Address), ".mlxjet.com") > 0) Then
                    strAddress = olkRecipient.Address & ".mlxjet.com"
                    Set olkNewRecipient = Session.CreateRecipient(strAddress)
                    olkNewRecipient.Type = olBCC
                    olkNewRecipient.Type = olkRecipient.Type
                    Item.Recipients.Add olkNewRecipient
                    olkRecipient.Delete
                End If
            End If
        Next
        Item.Save
    End If
    Item.Recipients.ResolveAll
End Sub
0
Comment
Question by:flipside1212
  • 8
  • 8
16 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 210 total points
Comment Utility
Hi, flipside1212.

Sorry about that.  The code below fixes this.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    Dim olkRecipient As Outlook.Recipient, _

        olkNewRecipient As Outlook.Recipient, _

        strAddress As String, _

        intIndex As Integer

    If Item.Class = olMail Then

        For intIndex = Item.Recipients.Count To 1 Step -1

            Set olkRecipient = Item.Recipients(intIndex)

            If InStr(1, olkRecipient.Address, "@") Then

                If Not (InStr(1, LCase(olkRecipient.Address), ".mlxjet.com") > 0) Then

                    strAddress = olkRecipient.Address & ".mlxjet.com"

                    Set olkNewRecipient = Item.Recipients.Add(strAddress)

                    olkNewRecipient.Type = olBCC

                    olkNewRecipient.Type = olkRecipient.Type

                    olkRecipient.Delete

                End If

            End If

        Next

        Item.Save

    End If

    Item.Recipients.ResolveAll

End Sub

Open in new window

0
 
LVL 1

Author Comment

by:flipside1212
Comment Utility
Perfect!

I asked you about this before but I don't think I was clear on what the problem was. I have a tendency to muddle things. I've tried this out and it works perfectly. Thank you. Do you ever do contract work?
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Sorry, if you asked I don't remember.  

Yes, I do contract work occasionally.  That typically depends on the work (i.e. the complexity involved) and how much legal paperwork is involved.  I have a full-time job and don't have a lot of time to devote to outside work, so I shy away from anything too complex.  I also shy away from anything that requires involves much in the way of legal issues.  I'm always willing to discuss a project though.  My email address is in my profile if you want to contact me.
0
 
LVL 1

Author Comment

by:flipside1212
Comment Utility
I also was wondering if you know if images can be globally enabled within the macro. (Instead of having to go to Tools --> Trust Center --> etc.)
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Sorry, I don't understand.  What images are you talking about?
0
 
LVL 1

Author Comment

by:flipside1212
Comment Utility
You know how Outlook blocks automatic download of images by default? Can you write into the macro a function to make it so images aren't blocked. (So you don't have to manually enable images by going throught the menu).
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Not sure if that's possible or not.  I'll look into it.  You could always add the sender to the "Safe Senders" list.  
0
 
LVL 1

Author Closing Comment

by:flipside1212
Comment Utility
Great!!!
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 76

Expert Comment

by:David Lee
Comment Utility
This macro deals with sending items.  Are you asking if there is a way to do something in an item you send that'll cause pictures in your message to be automatically downloaded?  If so, the answer is no.  If that were possible, then there'd be no point to Outlook security since every sender could control downloading images.
0
 
LVL 1

Author Comment

by:flipside1212
Comment Utility
No, I'm just asking if there is a way to enable images for anyone that uses your macro instead of having them go through the tool menus to manually do it. I'm asking because there are people who want to use this macro you've created to add .mlxjet.com to their emails but it would also be nice if the macro would automatically enable the download of images on the machine that has the macro installed as they have sufficient virus and spam protection in place and would like to generally have emails show up with images.
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Got it.  I was confused because the macro deals with outbound messages while downloading pictures deals with received messages.  Doing this does not require any code.  The users can change the setting in Outlook.

1.  For Outlook 2003 and earlier: http://office.microsoft.com/en-us/outlook/HP073107391033.aspx
2.  For Outlook 2007: http://office.microsoft.com/en-us/outlook/HP012300401033.aspx?pid=CH100622191033
0
 
LVL 1

Author Comment

by:flipside1212
Comment Utility
You know, I really appreciate you going the extra miles for my questions but I was asking if it is possible to write this into a macro so that users don't have to manually enable images. In other words, can you write a function into the original macro you gave me that will automatically enable images on incoming messages? I realize that one thing has nothing to do with the other but I thought if the two different functions were installed into the same macro then it would save installation time.

The whole point of my question is this:

I basically don't want the users to have to go through the instructions you gave in the previous post as it may seem easy for us, but it's hard for them. Having it automatically enable global image download would make everyones life really easy!~
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
I know it's just terminology, but a macro is a given SUB or FUNCTION in Outlook.   So, when you initially asked about doing this I'm thinking that you want this additional capability written into that subroutine.  That's why I was confused.  Putting code to change that setting in a block of code that fires every time an item is sent didn't seem to make sense.  Now I understand that when by macro you just meant code.  So, yes, I can write this capability as an additional macro.  The code below does work for Outlook 2003 and 2007.  I'm not sure about other versions.
Sub UnblockPictures()

    Dim objShell As Object, arrVersionInfo As Variant

    arrVersionInfo = Split(Application.Version, ".")

    Set objShell = CreateObject("Wscript.Shell")

    objShell.RegWrite "HKCU\Software\Microsoft\Office\" & arrVersionInfo(0) & ".0\Outlook\Options\Mail\BlockExtContent", 0, "REG_DWORD"

    Set objShell = Nothing

End Sub

Open in new window

0
 
LVL 1

Author Comment

by:flipside1212
Comment Utility
Wow, sweet! Thank you
0
 
LVL 1

Author Comment

by:flipside1212
Comment Utility
except, can I just add that after the end of the other macro code? I tried that and it didn't change the setting. I'm sorry, I know nothing about this. if you could tell me how to invoke it that would be awesome!
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Yes, you can just copy and paste it into Outlook below the code you already have.  To run it, click Tools > Macro > Macros, select it and click the Run button.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Create high volume marketing opportunities using email signatures with these top 10 DOs and DON'Ts of email signature marketing.
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…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

743 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

12 Experts available now in Live!

Get 1:1 Help Now