• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 382
  • Last Modified:

Outlook: Auto-Reply to Person in Delivery Options "Have reply sent to" not the online service in the "From" field.

When I compile the solution (id 21738004) given by Bluedevilfan in Outlook 2007 (i.e. Version 12) (I'm using Microsoft Exchange also) I get a number of errors.  A missing End If and an End With that should have been an End If seems to sort some of it.  However the program stops on the Set redOriginal = CreateObject("Redemption.SafeMailItem") line with "The operation failed" message. Can someone fix this?
0
FaithfulWon
Asked:
FaithfulWon
  • 6
  • 5
1 Solution
 
David LeeCommented:
Hi, FaithfulWon.

I can't find the question you referred to.  Can you supply a link to it?
0
 
FaithfulWonAuthor Commented:
Thanks for getting back to me.  I'm going home now from work.  I won't be looking at this again until tomorrow morning.
0
Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

 
David LeeCommented:
You're welcome.

I corrected the End If problems.  The other error

    redOriginal = CreateObject("Redemption.SafeMailItem")

is occuring because you don't have Outlook Redemption installed.  the author of the original question wanted to use it.  I can remove that portion of the code if you want, but that will cause problems if you are using Outlook 2003 or earlier.  Prior to 2007 Outlook contained a security feature that prevented code from sending messages or accessing email addresses without the user's permission.  Redemtion is one way to work around that.  If you have Outlook 2007, then removing the Redemtion specific code won't cause any problems.  If you're using Outlook 2003 or earlier, then removing the code will kill this as an automatic process.
'Macro Code Begins Here
Private WithEvents objInboxItems As Items

Private Sub Application_Startup()
    Set objInboxItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Application_Quit()
    Set objInboxItems = Nothing
End Sub

Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
    Dim redOriginal As Object, _
        redResponse As Object
    If Item.Class = olMail Then
        Set redOriginal = CreateObject("Redemption.SafeMailItem")
        redOriginal.Item = Item
        If redOriginal.SenderEmailAddress = "jobseekers@domain.com" Then
            Set redResponse = CreateObject("Redemption.SafeMailItem")
            With redResponse
                .Item = Application.CreateItem(olMailItem)
                .Recipients.Add redOriginal.ReplyRecipientNames
                'Replace the subject text on the following line with your subject
                .Subject = "My Subject"
                'Replace the body text on the following line with your text
                .Body = "My message."
                .Send
            End With
        End If
    End If
    Set redResponse = Nothing
    Set redOriginal = Nothing
End Sub

Open in new window

0
 
FaithfulWonAuthor Commented:
I am using Outlook 2007 so we don't need the redemption specific code.  However I'm not sure what that means in relation to changes to the code. Can you tell me which items need to be taken out?  I also don't want it to run every time the client is opened.  Can I use the code as an ordinary macro which is run from the Tools- Macro menu? Thanks for your help.
0
 
David LeeCommented:
"Can you tell me which items need to be taken out?"
I'll change the code.  

"I also don't want it to run every time the client is opened."
That will kill an automatic response.  In other words, you'll have to select a message and run the macro for a response to be sent.  Is that what you want?
0
 
FaithfulWonAuthor Commented:
I guess the complication arises from the fact that I want to run the macro on the inbox of another account -not the default- that is set up on the same Outlook 2007 client.  I've already had problems trying to do that to move attachments using a macro and had to use the PickFolder command to select the folder first.  I could reuse this code for auto replies as well but I'm not sure how it will work in the ThisOutlookSession module.

For the time being just send me the changed code and I'll experiment with it and get back to you with any problems.  Thanks.
0
 
David LeeCommented:
Here's the code modified to remove Redemption.

This code can be modified to run against a folder in another mailbox.  I included code and instructions for doing that.


'Macro Code Begins Here
Private WithEvents objInboxItems As Items

Private Sub Application_Startup()
    Dim olkRecipient As Outlook.Recipient

    'The next line tells the code to monitor the local inbox'
    Set objInboxItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items

    'The next series of lines tells the code to monitor a shared inbox'
    Set olkRecipient = Session.CreateRecipient("someone@company.com")
    olkRecipient.ResolveAll
    Set objInboxItems = Session.GetSharedDefaultFolder(olkRecipient,olFolderInbox).Items

    'Remove or comment out one of the two approaches above'

End Sub

Private Sub Application_Quit()
    Set objInboxItems = Nothing
End Sub

Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
    Dim olkResponse As Outlook.MailItem
    If Item.Class = olMail Then
        If Item.SenderEmailAddress = "jobseekers@domain.com" Then
            Set olkResponse = Application.CreateItem(olMailItem)
            With olkResponse
                .Item = Application.CreateItem(olMailItem)
                .Recipients.Add redOriginal.ReplyRecipientNames
                'Replace the subject text on the following line with your subject
                .Subject = "My Subject"
                'Replace the body text on the following line with your text
                .Body = "My message."
                .Send
            End With
        End If
    End If
    Set olkResponse = Nothing
End Sub

Open in new window

0
 
FaithfulWonAuthor Commented:
Hi BlueDevilFan, (is that name because you support Manchester City in the UK Premier League?),
I've been getting a number of errors as I test the new version related to objects not supporting methods.  For example the ResolveAll method is not supported in line 12 (an error message I cleared by changing ResolveAll to Resolve) and there is a similar problem on line 29 (a property or method not supported - RunTime error 438).  Also I don't understand the redOriginal expression in line 30.
0
 
David LeeCommented:
Sorry, I missed a couple of things that needed to be fixed.  Please try this version.

"is that name because you support Manchester City in the UK Premier League?"
No, but you aren't the first person to ask.  I'm a fan of Duke University in North Carolina.
'Macro Code Begins Here
Private WithEvents objInboxItems As Items

Private Sub Application_Startup()
    Dim olkRecipient As Outlook.Recipient

    'The next line tells the code to monitor the local inbox'
    Set objInboxItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items

    'The next series of lines tells the code to monitor a shared inbox'
    Set olkRecipient = Session.CreateRecipient("someone@company.com")
    olkRecipient.Resolve
    Set objInboxItems = Session.GetSharedDefaultFolder(olkRecipient, olFolderInbox).Items

    'Remove or comment out one of the two approaches above'

End Sub

Private Sub Application_Quit()
    Set objInboxItems = Nothing
End Sub

Private Sub objInboxItems_ItemAdd(ByVal Item As Object)
    Dim olkResponse As Outlook.MailItem
    If Item.Class = olMail Then
        If Item.SenderEmailAddress = "jobseekers@domain.com" Then
            Set olkResponse = Application.CreateItem(olMailItem)
            With olkResponse
                .Recipients.Add Item.ReplyRecipientNames
                'Replace the subject text on the following line with your subject
                .Subject = "My Subject"
                'Replace the body text on the following line with your text
                .Body = "My message."
                .Send
            End With
        End If
    End If
    Set olkResponse = Nothing
End Sub

Open in new window

0
 
FaithfulWonAuthor Commented:
It took a few iterations but the solution does what I need now.
0

Featured Post

Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now