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.
 
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
 
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!
 
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
 
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
 
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
 
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?
 
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
 
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

AD4NxxS.png

Like that?
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
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
X Run macro automatically when a mail appears in the sent folder Using Outlook 5
J Calendar events created on iPhone automatically changing default alert from 'None' to 'Time of Event' Using Outlook.com accounts in Outlook 0
Z Automatically adjust Outlook Reading Pane from bottom to right depending on portrait or landscape window Using Outlook 1
G Automatically delete email when a condition is met Outlook VBA and Custom Forms 1
Hornblower409 Automatically or Manually Backup Multiple Versions of VbaProject.OTM Outlook VBA and Custom Forms 1
B Outlook 2019 Automatically move email after assigning category Using Outlook 4
G automatically choosing "add to autocorrect" option Using Outlook 0
L Why are some email automatically going to "archive" Using Outlook 2
Z Outlook 365 Automatically assign categories to incoming mail in a shared folder Round Robin Outlook VBA and Custom Forms 1
G Automatically delete messages in the synchronization folder Outlook VBA and Custom Forms 3
C Automatically Insert Recipient Name from To Field Outlook VBA and Custom Forms 4
E Remove flag automatically Using Outlook 4
T Outlook 365 Move newly created tasks automatically on save. Outlook VBA and Custom Forms 1
M Outlook 365 Switching from AOL to Yahoo automatically Using Outlook 5
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 4
B Zoom automatically next email item (VBA) Outlook VBA and Custom Forms 2
Paul Hobbs Automatically accept "Empty Folders" prompt Outlook VBA and Custom Forms 6
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 Using Outlook 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 Using Outlook 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

Similar threads

Back
Top