![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
I wish to set a rule to perform the following:
1. Transfer the mail to a folder called "rejected mail" when the e-mail address contain "abc.com" and it is not in my address book. 2. Send a notification e-mail to the sender when the above action is performed. 3. I tried to set the above using Outlook's rules. But, it only manages to send the notification once. If I receive the e-mail from the same unauthorized person again, Outlook will not send another notification to the sender again. As a result of that, I'm thinking whether I could set up a script/ macro to auto reply to the sender when a new mail reach the "rejected mail" folder. Can anyone help me with this? |
Ads |
#2
|
|||
|
|||
![]()
You can do this with a "run a script" rule action, which calls not an external script but a VBA procedure with a MailItem or MeetingItem as its parameter. That item is processed by the code:
Sub RunAScriptRuleRoutine(MyMail As MailItem) Dim strID As String Dim olNS As Outlook.NameSpace Dim msg As Outlook.MailItem Dim rpl as Outlook.MailItem strID = MyMail.EntryID Set olNS = Application.GetNamespace("MAPI") Set msg = olNS.GetItemFromID(strID) ' do stuff with msg, e.g. Set rpl = msg.Reply rpl.Body = "some extra text" & vbCrLf & rpl.Body rpl.Send Set msg = Nothing Set olNS = Nothing End Sub See http://www.outlookcode.com/d/code/zaphtml.htm#ol2002 for another example. -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "ah" wrote in message ... I wish to set a rule to perform the following: 1. Transfer the mail to a folder called "rejected mail" when the e-mail address contain "abc.com" and it is not in my address book. 2. Send a notification e-mail to the sender when the above action is performed. 3. I tried to set the above using Outlook's rules. But, it only manages to send the notification once. If I receive the e-mail from the same unauthorized person again, Outlook will not send another notification to the sender again. As a result of that, I'm thinking whether I could set up a script/ macro to auto reply to the sender when a new mail reach the "rejected mail" folder. Can anyone help me with this? |
#3
|
|||
|
|||
![]()
Try using this code as a basis for what you want to do. The Item_Add event
will fire when an e-mail is moved to the folder that you specify, and then you can work with the message in any way you want. Keep in mind that the Item_Add event is flaky and may not fire if a large number of messages are moved/copied/delivered to a folder at the same time. '--------------------------------------------------------------------------------------- ' Module : clsMailItemTrapper ' Usage : ' : In the ThisOutlookSession module, you must instantiate this class properly ' : so it will run while Outlook is open ' ' e.g.: ' Dim myTrapper As clsMailItemTrapper ' ' Private Sub Application_Startup() ' Set myTrapper = New clsMailItemTrapper ' End Sub ' Private Sub Application_Quit() ' Set myTrapper = Nothing ' End Sub '--------------------------------------------------------------------------------------- Option Explicit Dim WithEvents objMonitoredFolderItems As Outlook.Items Private objMonitoredFolder As Outlook.MAPIFolder Private objNS As Outlook.NameSpace Private Sub Class_Initialize() On Error GoTo EH: Set objNS = Application.GetNamespace("MAPI") 'Method 1: if you know the EntryID for the folder... Set objMonitoredFolder = objNS.GetFolderFromID("000000003F89017490AEDA4098A 93E729EC138D402890000") 'Method 2: set to a default folder Set objMonitoredFolder = objNS.GetDefaultFolder(olFolderInbox) 'Method 3: if you know the full path to the folder Set objMonitoredFolder = OpenMAPIFolder("PST Name\RootFolderName\SubFolder") Set objMonitoredFolderItems = objMonitoredFolder.Items EH: If Err.Number 0 Then Exit Sub End If End Sub Private Sub Class_Terminate() Set objMonitoredFolder = Nothing Set objMonitoredFolderItems = Nothing Set objNS = Nothing End Sub Private Sub objMonitoredFolderItems_ItemAdd(ByVal Item As Object) On Error GoTo EH: If Item.Class olMail Then Exit Sub Dim objMail As Outlook.MailItem Set objMail = Item 'Do something with the message Set objMail = Nothing EH: If Err.Number 0 Then Resume Next End If End Sub '************************************************* ***************************** 'Custom procedu OpenMAPIFolder(ByVal strPath) 'Purpose: Return a MAPIFolder from Path argument 'Returns: MAPIFolder object '************************************************* ***************************** Function OpenMAPIFolder(ByVal strPath) As Outlook.MAPIFolder On Error GoTo OpenMAPIFolder_Error Dim objFldr As Outlook.MAPIFolder Dim strDir As String Dim strName As String Dim i As Integer If strPath = "" Then Exit Function If Left(strPath, Len("\")) = "\" Then strPath = Mid(strPath, Len("\") + 1) Else Set objFldr = ActiveExplorer.CurrentFolder End If While strPath "" i = InStr(strPath, "\") If i Then strDir = Left(strPath, i - 1) strPath = Mid(strPath, i + Len("\")) Else strDir = strPath strPath = "" End If If objFldr Is Nothing Then Set objFldr = objNS.Folders(strDir) On Error GoTo 0 Else Set objFldr = objFldr.Folders(strDir) End If Wend Set OpenMAPIFolder = objFldr On Error GoTo 0 Exit Function OpenMAPIFolder_Error: MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure OpenMAPIFolder" End Function -- Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "ah" wrote: I wish to set a rule to perform the following: 1. Transfer the mail to a folder called "rejected mail" when the e-mail address contain "abc.com" and it is not in my address book. 2. Send a notification e-mail to the sender when the above action is performed. 3. I tried to set the above using Outlook's rules. But, it only manages to send the notification once. If I receive the e-mail from the same unauthorized person again, Outlook will not send another notification to the sender again. As a result of that, I'm thinking whether I could set up a script/ macro to auto reply to the sender when a new mail reach the "rejected mail" folder. Can anyone help me with this? |
#4
|
|||
|
|||
![]()
Hi Sue;
Thanks for your prompt reply.It really helps me a lot! I found that the script manages to auto reply back to the sender together with their original message. I'm really glad with that. Can I know whether there is any way that I could even send back the attachment together with the notification e-mail when the sender sends me an attachment along?This is due to the fact that the sender might need to know which e-mail and attachments are being rejected. Thanks for your great help. "Sue Mosher [MVP-Outlook]" wrote: You can do this with a "run a script" rule action, which calls not an external script but a VBA procedure with a MailItem or MeetingItem as its parameter. That item is processed by the code: Sub RunAScriptRuleRoutine(MyMail As MailItem) Dim strID As String Dim olNS As Outlook.NameSpace Dim msg As Outlook.MailItem Dim rpl as Outlook.MailItem strID = MyMail.EntryID Set olNS = Application.GetNamespace("MAPI") Set msg = olNS.GetItemFromID(strID) ' do stuff with msg, e.g. Set rpl = msg.Reply rpl.Body = "some extra text" & vbCrLf & rpl.Body rpl.Send Set msg = Nothing Set olNS = Nothing End Sub See http://www.outlookcode.com/d/code/zaphtml.htm#ol2002 for another example. -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "ah" wrote in message ... I wish to set a rule to perform the following: 1. Transfer the mail to a folder called "rejected mail" when the e-mail address contain "abc.com" and it is not in my address book. 2. Send a notification e-mail to the sender when the above action is performed. 3. I tried to set the above using Outlook's rules. But, it only manages to send the notification once. If I receive the e-mail from the same unauthorized person again, Outlook will not send another notification to the sender again. As a result of that, I'm thinking whether I could set up a script/ macro to auto reply to the sender when a new mail reach the "rejected mail" folder. Can anyone help me with this? |
#5
|
|||
|
|||
![]()
See http://www.outlookcode.com/d/code/copyatts.htm for a code sample that shows how to copy attachments from one item to another.
-- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "ah" wrote in message ... Hi Sue; Thanks for your prompt reply.It really helps me a lot! I found that the script manages to auto reply back to the sender together with their original message. I'm really glad with that. Can I know whether there is any way that I could even send back the attachment together with the notification e-mail when the sender sends me an attachment along?This is due to the fact that the sender might need to know which e-mail and attachments are being rejected. |
#6
|
|||
|
|||
![]()
Hi Sue;
I faced some problem after I placed in the script. Hope that you could assist me on that. The rules that I've set are as follows: 1. Move the file to a folder called "reject" when I receive an e-mail from a sender called "ack" 2. then, run the script that you provide . I found that the system managed to transfer the file to the reject folder. At the same time, when I refer back to the sent item in my mail box, I can see teh auto reject mail in my sent item folder. It seems like everything is working well and the system already sent out the auto reject message via the script. However, when I check with the sender, the sender did not receive any auto reject message from me. Kindly advice me on what should I do to resolve this issue. Previously when I try on my own mailbox, everything seems to be fine. But, now when I tried with the public mailbox, the auto reject mail was not being sent out to the sender Thanks in advance "Sue Mosher [MVP-Outlook]" wrote: You can do this with a "run a script" rule action, which calls not an external script but a VBA procedure with a MailItem or MeetingItem as its parameter. That item is processed by the code: Sub RunAScriptRuleRoutine(MyMail As MailItem) Dim strID As String Dim olNS As Outlook.NameSpace Dim msg As Outlook.MailItem Dim rpl as Outlook.MailItem strID = MyMail.EntryID Set olNS = Application.GetNamespace("MAPI") Set msg = olNS.GetItemFromID(strID) ' do stuff with msg, e.g. Set rpl = msg.Reply rpl.Body = "some extra text" & vbCrLf & rpl.Body rpl.Send Set msg = Nothing Set olNS = Nothing End Sub See http://www.outlookcode.com/d/code/zaphtml.htm#ol2002 for another example. -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "ah" wrote in message ... I wish to set a rule to perform the following: 1. Transfer the mail to a folder called "rejected mail" when the e-mail address contain "abc.com" and it is not in my address book. 2. Send a notification e-mail to the sender when the above action is performed. 3. I tried to set the above using Outlook's rules. But, it only manages to send the notification once. If I receive the e-mail from the same unauthorized person again, Outlook will not send another notification to the sender again. As a result of that, I'm thinking whether I could set up a script/ macro to auto reply to the sender when a new mail reach the "rejected mail" folder. Can anyone help me with this? |
#7
|
|||
|
|||
![]()
Did you check the address of the message in Sent Items? Maybe the sender put the wrong ReplyTo address on the incoming message, so that message went out but never reached the original sender?
You might also try using two rules for this instead of one. -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "ah" wrote in message ... Hi Sue; I faced some problem after I placed in the script. Hope that you could assist me on that. The rules that I've set are as follows: 1. Move the file to a folder called "reject" when I receive an e-mail from a sender called "ack" 2. then, run the script that you provide . I found that the system managed to transfer the file to the reject folder. At the same time, when I refer back to the sent item in my mail box, I can see teh auto reject mail in my sent item folder. It seems like everything is working well and the system already sent out the auto reject message via the script. However, when I check with the sender, the sender did not receive any auto reject message from me. Kindly advice me on what should I do to resolve this issue. Previously when I try on my own mailbox, everything seems to be fine. But, now when I tried with the public mailbox, the auto reject mail was not being sent out to the sender Thanks in advance "Sue Mosher [MVP-Outlook]" wrote: You can do this with a "run a script" rule action, which calls not an external script but a VBA procedure with a MailItem or MeetingItem as its parameter. That item is processed by the code: Sub RunAScriptRuleRoutine(MyMail As MailItem) Dim strID As String Dim olNS As Outlook.NameSpace Dim msg As Outlook.MailItem Dim rpl as Outlook.MailItem strID = MyMail.EntryID Set olNS = Application.GetNamespace("MAPI") Set msg = olNS.GetItemFromID(strID) ' do stuff with msg, e.g. Set rpl = msg.Reply rpl.Body = "some extra text" & vbCrLf & rpl.Body rpl.Send Set msg = Nothing Set olNS = Nothing End Sub See http://www.outlookcode.com/d/code/zaphtml.htm#ol2002 for another example. "ah" wrote in message ... I wish to set a rule to perform the following: 1. Transfer the mail to a folder called "rejected mail" when the e-mail address contain "abc.com" and it is not in my address book. 2. Send a notification e-mail to the sender when the above action is performed. 3. I tried to set the above using Outlook's rules. But, it only manages to send the notification once. If I receive the e-mail from the same unauthorized person again, Outlook will not send another notification to the sender again. As a result of that, I'm thinking whether I could set up a script/ macro to auto reply to the sender when a new mail reach the "rejected mail" folder. Can anyone help me with this? |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Reply macro... | [email protected] | Outlook and VBA | 4 | June 2nd 06 11:53 AM |
script to extract sender ip addresses | JTL | Outlook and VBA | 1 | April 25th 06 06:34 AM |
Setting the auto-archiving folder via script | Thomas | Outlook and VBA | 2 | March 8th 06 09:26 AM |
auto reply | GT | Outlook Express | 3 | February 17th 06 08:09 PM |
Reply going to Sender and Not List | Joe | Outlook Express | 0 | January 17th 06 09:43 PM |