PDA

View Full Version : Outlook MaiItem



CicoMico
06-04-2007, 02:06 AM
Hello!

I'm trying to create outlook mail rules to put incoming mail into it's folder. I have subscription in several newsletters & need to put each mail from each newsletter into it's own personal folder. The problem is, that if address is in CC as second, or third place nothing happens. Here s the code:


Dim defaultMailItem As MailItem

For Each defaultMailItem In defaultInbox.Items
If defaultMailItem.To = "XX@XX.com" Or defaultMailItem.CC = "XX@XX.com" Then
Call MoveMail(defaultMailItem, customInbox.Folders.Item("XX"). _
Folders.Item("XXX").Folders.Item("XXX").EntryID)
End If
Next defaultMailItem


And moving code:


Dim defaultNameSpace As Outlook.Namespace
Dim defaultMoveMailItem As MailItem

Set defaultMoveMailItem = defaultMailItem.Copy

defaultMoveMailItem.Move
Destfldr:=defaultNameSpace.GetFolderFromID(strTargFldrID)

defaultMailItem.Delete


any help?
thax

Edited 4-Jun-06 by geekgirlau. Reason: insert vba tags

mvidas
06-04-2007, 06:52 AM
CocoMico,

You can use InStr to see if the email address string is in the .to or .cc, like:'If defaultMailItem.To = "XX@XX.com" Or defaultMailItem.CC = "XX@XX.com" Then
If InStr(1, defaultMailItem.To, "XX@XX.com", vbTextCompare) > 0 Or _
InStr(1, defaultMailItem.CC, "XX@XX.com", vbTextCompare) > 0 ThenMatt

CicoMico
06-04-2007, 07:01 AM
CocoMico,

You can use InStr to see if the email address string is in the .to or .cc, like:'If defaultMailItem.To = "XX@XX.com" Or defaultMailItem.CC = "XX@XX.com" Then
If InStr(1, defaultMailItem.To, "XX@XX.com", vbTextCompare) > 0 Or _
InStr(1, defaultMailItem.CC, "XX@XX.com", vbTextCompare) > 0 ThenMatt

hmmm... i'll try that. thanx!

CicoMico
06-05-2007, 03:48 AM
that peace of code works! thanx! just another question. how can i disable outlook's security warnings? (a program is trying to access email addresses). i can't use third party software...

mvidas
06-05-2007, 06:12 AM
Luckily I still have outlook 2000 here at work (no security warnings), I can't install software either here.
The short answer: you can't disable those security warnings. part of outlook unfortunately. there are somewhat lengthy workarounds but for what you're looking for, it doesnt seem worth it.
Have you considered just using Message Rules for this?

What you could also do is use an outlook add-in to automatically get rid of the popup ( http://www.mapilab.com/outlook/security ) It is free and doesnt actually need to be installed, just gets integrated into outlook.
You could also try the software called ClickYes, also doesnt need to be installed, but would be standalone software meant to 'catch' the security popup and automatically click yes

CicoMico
06-05-2007, 06:38 AM
thanx, i'll try that. i can't use rules, because i have many mailing lists and exchange server is just limited in number of rules.

CicoMico
06-14-2007, 03:24 AM
hey! another prob arises... when i have delivery report in my inbox, macro stops with error... any help?

mvidas
06-14-2007, 05:52 AM
Hmm.. what error? Type Mismatch? If so, try this, and if not, we need more details:Dim defaultMailItem As Object

For Each defaultMailItem In defaultInbox.Items
If TypeName(defaultMailItem) = "MailItem" Then
'rest of code to check To and CC
End If
Next defaultMailItem

CicoMico
06-14-2007, 06:15 AM
yep, that's it. thanx! i hope it will work...

CicoMico
06-18-2007, 05:59 AM
hmm... unfortunately, if i recieve read receipt, it keeps getting me this Mismatch error...

mvidas
06-18-2007, 06:15 AM
Hmm.. I hoped that would work, I never send messages with return receipts so I've never had to deal with it.

Based on a quick google search, the following should work:For Each defaultMailItem In defaultInbox.Items
If TypeName(defaultMailItem) = "MailItem" Then
If defaultMailItem.MessageClass = "IPM.Note" Then
'rest of code to check To and CC
End If
End If
Next defaultMailItemThe messageclass will return IPM.Note for messages, versus IPM.Report for receipts/delivery reports.

In all honesty you may not need to check the TypeName if you're gonna use this too, I'd use them both just to be safe though.

CicoMico
06-18-2007, 06:25 AM
ok. will try that. thx :bow: