Outlook 2010, copy an email into folder and mark copied email as read but keep original email as unread - outlook-2010

I have rules set up to copy emails containing certain keywords to specific folders and mark as read.
The problem i'm having is when it copies those emails to the folders it marks the original email in the inbox as read, and which can cause me to miss the message.
If i don't mark it as read then when i read it in the Inbox it stays unread in the specific folder.
I cant find any rule properties to accomplish this, anyone have any ideas?

Set the rules to copy to the target folders but not mark as read.
Put this untested code in the ThisOutlookSession module. Assumes the target folders are directly under the Inbox. If buried deeper, add .Folders as necessary.
Option Explicit
' one line for each target folder
Private WithEvents myOlItemsA As Outlook.Items
Private WithEvents myOlItemsB As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
' one line for each target folder
Set myOlItemsA = objNS.GetDefaultFolder(olFolderInbox).Folders("targetfoldernameA").Items
Set myOlItemsB = objNS.GetDefaultFolder(olFolderInbox).Folders("targetfoldernameB").Items
End Sub
' one copy of ItemAdd code for each target folder
Private Sub myOlItemsA_ItemAdd(ByVal item As Object)
On Error GoTo ErrorHandler
Dim Msg As Outlook.MailItem
If TypeName(item) = "MailItem" Then
Set Msg = item
Msg.Unread = False
End If
ProgramExit:
Set Msg = Nothing
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
Private Sub myOlItemsB_ItemAdd(ByVal item As Object)
' same code as for myOlItemsA
End Sub
Code based on this post Using VBA to read new Outlook Email?
The rules move mail to target folders. The ItemAdd code acts on the items added to the target folders.

Related

Macro in outlook to mark emails as read

I want to use a macro in outlook 2013. This macro is supposed to mark any emails arriving a specific folder ('work' folder) as read. I'm not familiar with vb. Any help/guidance is much appreciated!
No sure, I have heard this one before of wanting emails automatically read. You have two options:
a) Use Ctrl-A (select all mail in folder), Ctrl-Q (mark selection as read)
b) Use New Email Event something like:
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
vID = Split(EntryIDCollection, ",")
Dim i as Long, objMail as Outlook.MailItem
For i = 0 To UBound(vID)
Set objMail = Application.Session.GetItemFromID(vID(i))
objMail.Unread = False
Next i
End Sub
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
' version to select folder
Dim i As Long, objMail As Outlook.MailItem, mpfInbox As Outlook.Folder
Set mpfInbox = Application.GetNamespace("MAPI").Folders("YOURACCOUNT").Folders("[Gmail]").Folders("Sent Mail")
For i = 1 To mpfInbox.Items.Count
If mpfInbox.Items(i).Class = olMail Then
Set objMail = mpfInbox.Items.Item(i)
objMail.UnRead = False
End If
Next i
End Sub
You can set up a rule which can trigger your macro.
I'd not suggest working with the NewMailEx event because it is not fired in some case and may introduce issues. See Outlook NewMail event unleashed: the challenge (NewMail, NewMailEx, ItemAdd) for more information.

Outook. Delete Email

Is there a way where I can delete all the emails from a folder at a set time everyday when AutoArchive is disable on my system ? Typically I would use AutoArchive to resolve this but currently it is not an option.
Set up a daily recurring task, with a reminder and a unique subject.
In the ThisOutlookSession module
Option Explicit
Private Sub Application_Reminder(ByVal Item As Object)
If Item.MessageClass = "IPM.Task" Then
If Item.Subject = "Scheduled Deletion" Then
DeleteFromToBeDeleted
End If
End If
End Sub
Sub DeleteFromToBeDeleted()
Dim myFolder As Folder
Dim i As Long
Set myFolder = Application.GetNamespace("MAPI"). _
GetDefaultFolder(olFolderInbox).Folders("ToBeDeleted")
For i = myFolder.items.Count To 1 Step -1
myFolder.items(i).Delete
Next i
Set myFolder = Nothing
End Sub

Outlook 2010 change signature based on recipient

I was wondering if it was possible for when you enter a recipient's address for Outlook 2010 to automatically detect this address and change the signature accordingly? Just a general question.
I've had the same question and so far have not found the answer. As a nice workaround, I've successfully used the solution provided here: https://superuser.com/a/228633/74819. In the end you get a button on the toolbar allowing you to create a new message with a custom To address and a pre-defined body text (including signature) of your choice.
Now I actually find this method nicer than what I was looking for because it is more predictable. If the signature (and thus the message body) was changing based on the list of recipients, you would loose control over your text. Also, with a tool of your own, you can set more than just a signature.
Are you looking for a setting to do this or are you willing to work with a macro? If you're open to working with macros, see below and reply back with questions.
Public WithEvents goInspectors As Outlook.Inspectors
Public WithEvents myMailItem As Outlook.MailItem
Private Sub Application_Startup()
Initialize_Inspector
End Sub
Private Sub Initialize_Inspector()
Set goInspectors = Outlook.Application.Inspectors
End Sub
Private Sub goInspectors_NewInspector(ByVal Inspector As Inspector)
If Inspector.currentItem.Class = olMail Then
Set myMailItem = Inspector.currentItem
End If
End Sub
Private Sub myMailItem_PropertyChange(ByVal Name As String)
'The variable below should be modified for your situation.
'If you are in an Exchange environment, then you can use "last name, firstname"(caps-sensitive).
'If the the recipient is not in Outlook's address list, use "person#email.com"
customSignatureFor = "Lastname, Firstname"
'Use vbCrLf to account for enter/returns
oldSignature = "Respectfully," & vbCrLf & vbCrLf & "Phillip"
newSignature = "v/r," & vbcrlf & "Phil"
If Name = "To" Then
For i = 1 To myMailItem.Recipients.count
If InStr(myMailItem.Recipients(i), customSignatureFor) > 0 Then
tempstring = Replace(myMailItem.Body, oldSignature, newSignature)
myMailItem.Body = tempstring
End If
Next
End If
End Sub

Automatically moving email from Deleted Items folder to another folder

My company uses a cloud Exchange system that deletes emails when they have been in the Deleted Items folder for 30 days (we use Outlook 2010 clients). I want a script that would move all email from the Deleted Items folder to a second folder called "Trash". I was able to find most of the following script online but it isn't working for me and I'm not sure what is missing/incorrect. Any help is appreciated...
Sub MoveDeletedItems()
Dim oSource As Outlook.MAPIFolder
Dim oTarget As OutlookMAPIFolder
Dim oDummy As Object
Dim oToMove As Object
Dim colItems As Outlook.Items
Dim i As Long
Set oSource = Application.Session.GetDefaultFolder(olFolderDeletedItems)
Set oTarget = oSource.Folders.Folder("Trash")
Set colItems = oSource.Items
For i = colItems.Count To 1 Step -1
Set oToMove = colItems(i)
Set oDummy = oToMove.Move(oTarget)
Next
End Sub
Fist you have a lot of stuff going on you dont need
Here is an example with comments that can be run as a macro within outlook.
Sub MoveDeletedItems()
'setup some error checking
On Error GoTo err_rpt
Dim oSource As Outlook.MAPIFolder
Dim oTarget As Outlook.MAPIFolder
Dim oItem
'get the deleted Items folder
Set oSource = Application.Session.GetDefaultFolder(olFolderDeletedItems)
'get the folder under the Deleted Items folder called Trash
Set oTarget = oSource.Folders("Trash")
'loop through all the items in the source folder
For Each oMailItem In oSource.Items
'move the item to the target folder
oItem.Move oTarget
Next
err_rpt:
If Err.Number > 0 Then
MsgBox Err.Description
End If
'release the folders
Set oTarget = Nothing
Set oSource = Nothing
End Sub

Handle the incoming emails using vbscript

Problem: Handle the incoming emails using vbscript.
Outlook Version: Outlook 2000
Description: I cannot use VBA for this as I believe Outlook 2000 doesn't let you run a VBA script from the rules wizard and hence I have to use the Run a Program | VBScript method.
What I know: I know how to handle email from VBA like this
Sub Sample(MyMail As MailItem)
Dim strID As String, olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
'~~> Rest of the code
Set olMail = Nothing
Set olNS = Nothing
End Sub
I also know how to run the vbscript on the email which is already in the inbox. To run a vbscript in OL2000, you have to use Run A Program and point it to the vbs file. The Run A Script is not available in OL2000.
What I do not know: And this is where I need help. How to get the mail object which has not hit the mail inbox in VBS. Once I get the object then I can do the rest of the necessary operations.
You are correct that OL2000 cannot run a VBA macro from a rule, if this article is to be believed.
Here's how I handle incoming emails. It does use VBA but as far as I know, there isn't a way to do so in VBScript.
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub Items_ItemAdd(ByVal item As Object)
On Error Goto ErrorHandler
Dim Msg As Outlook.MailItem
If TypeName(item) = "MailItem" Then
Set Msg = item
'~~> do something with the new message here
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
This code should be pasted into the ThisOutlookSession module, then Outlook should be restarted.

Resources