PDA

View Full Version : Outlook set expiry date & redirect the email



alienblk1980
09-12-2017, 01:00 PM
Hi All,

Trying to establish whether is a possible set expiry date(30 days) for incoming emails then redirect that email to different recipients/groups.

I want to run that as outlook rule, triggered by certain keywords and then start a script. I have seen outlook scripts for setting expiry date(see below) but wondering whether someone could help me?

Thank you


Public WithEvents olItems As Items

Private Sub Application_Startup()
Set olItems = Application.Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub olItems_ItemAdd(ByVal Item As Object)
Dim strMsg As String
Dim nRes As Integer

If Item.ExpiryTime = #1/1/4501# Then
Item.ExpiryTime = DateAdd("m", 1, Item.ReceivedTime)
End If

Item.Save
End Sub

gmayor
09-13-2017, 12:32 AM
Are you sure that it's the expiry date parameter you want to change? If so then a script attached to a rule should do the job as the messages arrive e.g.


Sub SetLimitAndSendOnMessage(olItem As MailItem)
Dim olOutMail As Outlook.MailItem
Set olOutMail = olItem.Forward
With olOutMail
.To = "someone@somewhere.com"
.ExpiryTime = Date + 30
.Display
'.Send 'Enable after testing
End With
lbl_Exit:
Set olOutMail = Nothing
Exit Sub
End Sub


You can test the code by selecting a message in your InBox and running the following


Sub testMacro()
Dim olMsg As MailItem
On Error Resume Next
Set olMsg = ActiveExplorer.Selection.Item(1)
SetLimitAndSendOnMessage olMsg
lbl_Exit:
Exit Sub
End Sub

alienblk1980
09-13-2017, 02:56 AM
Yes I want to set expiry date for each incoming email and then forward that copy of that email(with expiry date).


I have tested and forwarding is working and in destination mailbox copy of email is there with expiry date but not for email from source mailbox.

Thank you

gmayor
09-13-2017, 04:19 AM
As I understand it the expiry date is an option relating to the sending of a message and not to a message that has been received. The expiry date is therefore set for the message you are actually sending, which is the forwarded copy.

alienblk1980
09-13-2017, 05:32 AM
Okay, what I would like this to work is for all incoming emails set expiry date to 30 days then forward copy of that email.

Is that possible?