Automatically Forward All Sent Mail and Delete After Send

Status
Not open for further replies.

undercover_smother

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server
Greetings,

I've tried a few options but none have worked. I'm trying to get all SENT emails from a 2010 email account to forward to another email account (on same server; I don't know if that is relevant) and to delete the forwarded email.

Some notes:
- This is to observe an employee that I oversee for suspected nefarious behavior (not ready to have franchise IT get involved yet...for many reasons)
- Attachment contents aren't relevant; attachment title is kind of relevant, but not mandatory
- Needs to be triggered by either a rule (less-ideal), or some kind of a listener in VBA (more ideal) - I don't want this person to see a rule with a script name in it

I've tried the code (from this site) below but it was not working:

Sub ChangeSubjectForward(Item As Outlook.MailItem)

Set myForward = Item.Forward
myForward.Recipients.Add "alias@domain.com"

' To BCC an address or DL, try this:
'myForward.BCC = "alias"

myForward.DeleteAfterSubmit = True

myForward.Send

End Sub
Perhaps it's just me doing something wrong. Anyone have any ideas?

Thanks in advance for the help.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Editing should work for about 10 min... I will double check the settings.

An itemsend macro would be best if you are doing it client side, but all they need to do is look in the VBA editor... they could also disable it by restarting outlook in safe mode. Automatically BCC All Messages Oh, and they'll see the BCC if they look in sent mail.

A better option would be the admin giving you mailbox rights - I'll have to double check, but i don't think he'd see it in permissions. Exchange also has the capability to forward mail sent to and from mailboxes (journaling or mail flow rules) - this would also be totally hidden from the user. Either is much better than using a macro - and totally secretive. But only the Exchange admin can set it up.

I would use mail flow, as mailbox rights would open the mailbox in your profile and you run the risk of marking mail read and tipping him off. Journaling is kind of a pita as messages are forwarded to the journal mailbox as attachments.

Monitoring Employees Email
 

undercover_smother

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server
Editing should work for about 10 min... I will double check the settings.

An itemsend macro would be best if you are doing it client side, but all they need to do is look in the VBA editor... they could also disable it by restarting outlook in safe mode. Automatically BCC All Messages Oh, and they'll see the BCC if they look in sent mail.

A better option would be the admin giving you mailbox rights - I'll have to double check, but i don't think he'd see it in permissions. Exchange also has the capability to forward mail sent to and from mailboxes (journaling or mail flow rules) - this would also be totally hidden from the user. Either is much better than using a macro - and totally secretive. But only the Exchange admin can set it up.

I would use mail flow, as mailbox rights would open the mailbox in your profile and you run the risk of marking mail read and tipping him off. Journaling is kind of a pita as messages are forwarded to the journal mailbox as attachments.

Monitoring Employees Email

Thank you for that - unfortunately Journaling or mail flow would require involving franchise IT while would open up issues that I don't want to have to answer to...until I can prove that what I think is happening, is happening.

The employee doesn't know anything about VBA so they'd never look in the editor. I can already use rules to automatically CC all sent messages to myself, so I guess I need to be able to just delete those messages after they are sent. When you use rules, the person doesn't see the CC unless they look in the sent folder.

Maybe a better question would be to ask how to automatically delete (perm) messages that are forwards from him to me? I tried setting up a rule that was like //FROM:employee//TO:me// but that didn't automatically trigger. It seemed like it was on a delay. the deletion rule did work if I manually told the rule to run, however.

Any thoughts? Thanks for help!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
You only need sent items? It might work to watch the sent folder and send as attachment, then delete the forward. This way you won't have the forward icon or the sent item.

Test this, forwarding messages you send to yourself. it goes in thisoutlooksession - then restart outlook.
Code:
Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
  Dim Ns As Outlook.NameSpace
  Set Ns = Application.GetNamespace("MAPI")
  Set Items = Ns.GetDefaultFolder(olFolderSentMail).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
  On Error Resume Next

  Dim objMsg As MailItem
  Set objMsg = Application.CreateItem(olMailItem)

   objMsg.To = "you@domain.com"
   objMsg.Subject = Item.Subject
   objMsg.Attachments.Add Item
      objMsg.DeleteAfterSubmit = True
objMsg.Send
   
   Set objMsg = Nothing

End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
BTW, you could do it for inbox too..
Add these lines after the similar originals:
Private WithEvents InboxItems As Outlook.Items
Set InboxItems = Ns.GetDefaultFolder(olFolderinbox).Items

Then duplicate the items_itemadd macro, renaming the copy Private Sub InboxItems_ItemAdd(ByVal Item As Object)

or create stubs and share the main macro:

Code:
Private WithEvents Items As Outlook.Items
Private WithEvents InboxItems As Outlook.Items

Private Sub Application_Startup()
  Dim Ns As Outlook.NameSpace
  Set Ns = Application.GetNamespace("MAPI")
  Set Items = Ns.GetDefaultFolder(olFolderSentMail).Items
  Set InboxItems = Ns.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
ForwardMessage Item
End Sub

Private Sub inboxItems_ItemAdd(ByVal Item As Object)
ForwardMessage Item
End Sub

Private Sub ForwardMessage(ByVal Item As Object)
  On Error Resume Next
  Dim objMsg As MailItem
  Set objMsg = Application.CreateItem(olMailItem)

   objMsg.To = "you@domain.com"
   objMsg.Subject = Item.Subject
   objMsg.Attachments.Add Item
      objMsg.DeleteAfterSubmit = True
objMsg.Send
   
   Set objMsg = Nothing

End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
actually, that is not working well for inbox items - they are marked read.

use this as the inbox stub:
Private Sub inboxItems_ItemAdd(ByVal Item As Object)
ForwardMessage Item
Item.UnRead = True
'Item.Save
End Sub
 

undercover_smother

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server
You only need sent items? It might work to watch the sent folder and send as attachment, then delete the forward. This way you won't have the forward icon or the sent item.

Test this, forwarding messages you send to yourself. it goes in thisoutlooksession - then restart outlook.
Code:
Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
  Dim Ns As Outlook.NameSpace
  Set Ns = Application.GetNamespace("MAPI")
  Set Items = Ns.GetDefaultFolder(olFolderSentMail).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
  On Error Resume Next

  Dim objMsg As MailItem
  Set objMsg = Application.CreateItem(olMailItem)

   objMsg.To = "you@domain.com"
   objMsg.Subject = Item.Subject
   objMsg.Attachments.Add Item
      objMsg.DeleteAfterSubmit = True
objMsg.Send
  
   Set objMsg = Nothing

End Sub

Thank you for this. I've tried this on my own system and it didn't seem to forward the mail.

That being said, I have Outlook 2016 and I need this for a computer running Outlook 2010 - I don't know if that makes a difference. I'm by no means a VBA pro but I don't see where the second sub above looks in the sent folder. The first names "Items" as the default sent mail folder but I don't see where it is called in the second sub. Am I missing something?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
it will work in 2007 and up.
These lines tell it where to watch:
Set Items = Ns.GetDefaultFolder(olFolderSentMail).Items
Set InboxItems = Ns.GetDefaultFolder(olFolderInbox).Items

the entire set of code needs to be in thisoutlooksession, you need macro security set to low and you need to restart outlook.

How to use Outlook's VBA Editor
Processing Incoming E-mails with Macros
 

undercover_smother

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server
it will work in 2007 and up.
These lines tell it where to watch:
Set Items = Ns.GetDefaultFolder(olFolderSentMail).Items
Set InboxItems = Ns.GetDefaultFolder(olFolderInbox).Items

the entire set of code needs to be in thisoutlooksession, you need macro security set to low and you need to restart outlook.

How to use Outlook's VBA Editor
Processing Incoming E-mails with Macros


Like that?
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
L Automatically forward ALL outgoing/sent emails to another email adddress (not just for a specific distribution list) Using Outlook 2
J Automatically forward email and apply template Outlook VBA and Custom Forms 0
O Forward a email with modified body Automatically. Outlook VBA and Custom Forms 0
B Automatically Forward Emails and Remove/Replace All or Part of Body Outlook VBA and Custom Forms 8
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
D Custom Search Folders not refreshing/updating automatically Using Outlook 0
M Automatically add senders first name to a greeting Outlook VBA and Custom Forms 1
C Add Form to Appointments Received, Automatically Outlook VBA and Custom Forms 6
Y Outlook 2013 Stop Outlook from automatically assigning categories to Tasks Using Outlook 0
A How to open a specific link automatically with outlook 2016 Outlook VBA and Custom Forms 6
P Automatically Categorize Meetings once they are accepted Outlook VBA and Custom Forms 5
W Automatically open attachments without automatically printing them Using Outlook 0
N How to set automatically the default or user defined Quickstyle Templates by Answer in Outlook Using Outlook 1
O Run macro automatically at sending an email Using Outlook 11
D Outlook 2016 automatically increment anniversaries Using Outlook 1
T Office 2013 no longer updating automatically Using Outlook 2
D Print attachments automatically and moves the mail to a new folder Outlook VBA and Custom Forms 9
A How to open a specific link automatically with outlook Outlook VBA and Custom Forms 13
L Automatically Insert Recipient Name from To Field Outlook VBA and Custom Forms 33
N how to sync automatically when outlook opens Using Outlook 10
A Sort emails into subfolders based on sender and deleting emails automatically Outlook VBA and Custom Forms 3
C Need VBA code to automatically save message outside outlook and add date Outlook VBA and Custom Forms 1
stephen li VBA Outlook send mail automatically by specified outlook mail box Outlook VBA and Custom Forms 1
R Make Enter Network Password Prompt Go Away Automatically Using Outlook 0
I Print Automatically Attachments Outlook VBA and Custom Forms 3
S Automatically selecting folders and deleting messages in Outlook VBA Outlook VBA and Custom Forms 7
M Outlook 2016 Rules Not Working Automatically Using Outlook 5
Diane Poremsky Automatically create a task when sending a message New Slipstick.com Articles 0
D Is it possible to automatically send an email when it is moved to a folder? Exchange Server Administration 1
A Automatically send email based on drop-down field? Outlook VBA and Custom Forms 2
M Automatically create event in calendar when task is created Outlook VBA and Custom Forms 1
Diane Poremsky Create Appointment From Email Automatically New Slipstick.com Articles 0
Cameron Piper Automatically update custom forms across multiple computers Outlook VBA and Custom Forms 1
T Automatically open link in email received Outlook VBA and Custom Forms 33
N Automatically file email messages Using Outlook 2
J Automatically Move Old Items from a Shared Mailbox to a .PST on a Network Drive Outlook VBA and Custom Forms 1
M Change default "automatically test account settings when Next is clicked" Using Outlook 1
D Automatically file message and reply to folder. Using Outlook 1
A Code to automatically delete message after sending Outlook VBA and Custom Forms 6
Diane Poremsky Automatically Create Contacts From Messages New Slipstick.com Articles 1
T Outlook 2010 emails do not refresh automatically Exchange Server Administration 1
L Save Mail Message to new folder created automatically Outlook VBA and Custom Forms 1
G Hae Rules NOT perform automatically? Using Outlook 1
F Automatically close email after selecting mark unread Using Outlook 1
nathandavies How to save emails to a specific folder on a network automatically using a macro Outlook VBA and Custom Forms 14
T Default inbox not automatically sending/receiving Using Outlook 1
Angger Microsoft Outlook 2010 Automatically Restarting Using Outlook 2
N Outlook Shared appointments automatically to Private Calendar Using Outlook 1
M Automatically move Outlook message to the specific folder when click on reply to all Using Outlook 4
I Automatically updates outlook 2011 address book Using Outlook 1

Similar threads

Top