Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Reading Outlook Messages

Reply
 
Old 02-26-2008   #11 (permalink)
Jacob Saaby Nielsen


 
 

Re: Reading Outlook Messages

Hey o [MVP],

I tried what you wrote, and I got a lot of errormessages. Using .Close()
I got:

Cannot find an overload for "Close" and the argument count: "0".
At C:\documents and settings\jsy\desktop\powershell scripts\NDRs.ps1:86 char:19
+ $eAlertMail.Close( <<<< )

I then found this post: http://weblogs.foxite.com/simonarnol...3/08/1265.aspx

Which says I could write 1 for discard without saving. I then get a whole
lotta this, after a little while:

Exception calling "Close" with "1" argument(s): "Your server administrator
has limited the number of items
you can open simultaneously. Try closing messages you have opened or removing
attachments and images
from unsent messages you are composing."

So that doesn't seem to work either.

Trying explicitely with .Close(0) I get:

Exception calling "Close" with "1" argument(s): "Your server administrator
has limited the number of items
you can open simultaneously. Try closing messages you have opened or removing
attachments and images
from unsent messages you are composing."
At C:\documents and settings\jsy\desktop\powershell scripts\NDRs.ps1:86 char:19
+ $eAlertMail.Close( <<<< 0)

.... after 247 messages processed It's very easy to see. Everything runs
smoothly for 247 messages, and bam - error
messages start hitting the screen.

Maybe I should start looking at some Exchange settings somewhere... ?

Running Outlook 2007 against an Exchange 2003 server btw.

Best Regards,
Jacob Saaby Nielsen

http://www.pipforhelvede.net
gmail: jacob DOT saaby
hotmail (IM/LinkedIN/Facebook): same as gmail
Quote:

> For calling the close method a method needs () behind it, hence the
> errors (method info ) you get.
>
Quote:

>> I tried using the .Close method, which results in no changes at all,
>> except for my screen being spammed
>>
> Greetings /\/\o\/\/
>
> "Jacob Saaby Nielsen" wrote:
>
Quote:

>> Hey Shay,
>>
>> one more thing: When I quit Outlook, I get a million (or rather, I'm
>> probably
>> getting
>> precisely 247, but I haven't stuck it out and counted - just pressed
>> cancel
>> ),
>> dialogues if I want to save the changes. Which is proably the
>> messages I
>> opened
>> with the script.
>> Best Regards,
>> Jacob Saaby Nielsen
>> http://www.pipforhelvede.net
>> gmail: jacob DOT saaby
>> hotmail (IM/LinkedIN/Facebook): same as gmail
Quote:

>>> I just wanted to check if you get the correct number of messages,
>>> the
>>> sender
>>> email address is not important.
>>> Anyway, do you get the same message "cannot read..." when you
>>> manually
>>> try
>>> to read the messages in Outlook?
>>> -----
>>> Shay Levi
>>> $cript Fanatic
>>> http://scriptolog.blogspot.com
>>>> Hey Shay,
>>>>
>>>> problem is - all mails sent to me, are from "Systemadministrator".
>>>> So
>>>> I would
>>>> get nowhere from doing that.
>>>> The e-mail address I need to extract is listed in the body of the
>>>> e-mail.
>>>> Anyway - only property I can even remotely relate to the sender,
>>>> would
>>>> be the userproperties property.
>>>> Or is there some other property I should go for ?
>>>> Best Regards,
>>>> Jacob Saaby Nielsen
>>>> http://www.pipforhelvede.net
>>>> gmail: jacob DOT saaby
>>>> hotmail (IM/LinkedIN/Facebook): same as gmail
>>>>> Can you try to list email senders only (don't process the body) ?
>>>>> How many do you get?
>>>>>
>>>>> -----
>>>>> Shay Levi
>>>>> $cript Fanatic
>>>>> http://scriptolog.blogspot.com
>>>>>> Hey guys,
>>>>>>
>>>>>> I'm doing this script, and as such it works ok. However, the
>>>>>> script
>>>>>> is
>>>>>> counting
>>>>>> 766 mails that match the subject filter,
>>>>>> and I'm only getting 247 e-mail addresses from the script.
>>>>>> So I poked around a bit, and noticed that a lot of the e-mail
>>>>>> messages
>>>>>> has
>>>>>> a "This item cannot be displayed in the reading
>>>>>> pane". Seems when I run the script, Outlook reaches a point where
>>>>>> I
>>>>>> have
>>>>>> too many open messages at the same time.
>>>>>> Anybody got a take on how to get around this ?
>>>>>> I'm pasting my sourcecode so you have the option of commenting my
>>>>>> code, what
>>>>>> to improve, or specifically how to get
>>>>>> around this "problem".
>>>>>> #
>>>>>> =================================================================
>>>>>> ==
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> ==========================================
>>>>>> #
>>>>>> # Script Information
>>>>>> #
>>>>>> # Title: NDRs.ps1
>>>>>> # Author: Jacob Saaby Nielsen ()
>>>>>> # Originally created: 06-02-2008 - 11:25:18
>>>>>> # Description: Extracts e-mail addresses and error-codes from
>>>>>> NDR
>>>>>> mails,
>>>>>> from a folder in Outlook
>>>>>> #
>>>>>> #
>>>>>> =================================================================
>>>>>> ==
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> ==========================================
>>>>>> #-------- Configurable Settings --------
>>>>>> # $subjectFilter needs to contain the word/words of the subject
>>>>>> you
>>>>>> want
>>>>>> to match
>>>>>> $subjectFilter = "User Forum"
>>>>>> # $NDRFolderName is the name of the folder in which you store the
>>>>>> NDRs. Folder
>>>>>> needs to be at the folderlevel just beneath Inbox
>>>>>> $NDRFolderName = "Undelivered"
>>>>>> # $NDRResultsFolder is the folder in which you want your results
>>>>>> file
>>>>>> located.
>>>>>> End with a backslash.
>>>>>> $NDRResultsFolder = "c:\"
>>>>>> # $NDRResultsFile is the name of the results file
>>>>>> $NDRResultsFile = "ndr-list.csv"
>>>>>> #-------- Non-configurable Settings - Do not change anything
>>>>>> after
>>>>>> this line --------
>>>>>> # Instantiating Outlook etc.
>>>>>> $olFolderInbox = 6;
>>>>>> $outlook = New-Object -com outlook.application;
>>>>>> $ns = $outlook.GetNameSpace("MAPI");
>>>>>> $NDRs =
>>>>>> $ns.GetDefaultFolder($olFolderInbox).Folders.Item("$NDRFolderName
>>>>>> ")
>>>>>> CLS
>>>>>> Write-Host 'Getting total number of eAlert mails...'
>>>>>> # Filter out all the files that are not meeting your subject
>>>>>> filter
>>>>>> $eAlertMails = $NDRs.Items | where {$_.Subject -match
>>>>>> $subjectFilter}
>>>>>> # Returns e-mail address from the message body, based on a
>>>>>> regular
>>>>>> expression
>>>>>> function get-Email([string]$MailBody)
>>>>>> {
>>>>>> $Regex = [regex]
>>>>>> "([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|((
>>>>>> [a
>>>>>> -
>>>>>> z
>>>>>> A
>>>>>> -Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})"
>>>>>> $Match = $Regex.Match($MailBody)
>>>>>> return $Match.Value
>>>>>> }
>>>>>> [int]$MailCounter = 1
>>>>>> foreach ($eAlertMail in $eAlertMails.Items)
>>>>>> {
>>>>>> # Create and update the progress bar
>>>>>> $status = "Processing mail {0} of {1}" -f $MailCounter,
>>>>>> $eAlertMails.Count
>>>>>> Write-Progress $status -PercentComplete ((100 /
>>>>>> $eAlertMails.Count)
>>>>>> *
>>>>>> $MailCounter
>>>>>> ) -Activity "Processing e-mails" -ID 1
>>>>>> # Add the string to the results file
>>>>>> Add-Content -path $NDRResultsFolder$NDRResultsFile -value
>>>>>> (get-Email
>>>>>> $eAlertMail.Body)
>>>>>> # Increment $MailCounter
>>>>>> $MailCounter++
>>>>>> }
>>>>>> Best Regards,
>>>>>> Jacob Saaby Nielsen
>>>>>> http://www.pipforhelvede.net
>>>>>> gmail: jacob DOT saaby
>>>>>> hotmail (IM/LinkedIN/Facebook): same as gmail



My System SpecsSystem Spec
Old 02-26-2008   #12 (permalink)
Jacob Saaby Nielsen


 
 

Re: Reading Outlook Messages

Hey Shay,

I found this: http://www.microsoft.com/communities...&cr=&sloc=&p=1

Question is:

- Can I invoke the garbage collector myself, and if so - how ?

Cause if that link has anything to it, I should be able to close the messages,
and then GC, let's say every 100 messages.

Best Regards,
Jacob Saaby Nielsen

http://www.pipforhelvede.net
gmail: jacob DOT saaby
hotmail (IM/LinkedIN/Facebook): same as gmail
Quote:

> I'm not sure.. can you try piping items instead of using the forach
> loop, as in:
>
> $eAlertMails.Items | foreach {...}
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
Quote:

>> Hey Shay,
>>
>> yeah that's how I originally found out, by poking around the message
>> list
>> in Outlook.
>> I don't really see anything when my script runs, other than it goes
>> from
>> "ok, it's processing something",
>> to "ok, now it's just skipping through everything".
>> I can also see it in the generated text file. Suddenly there are gaps
>> of
>> 2-3 lines in Excel. Then some
>> more e-mail addresses. Which is probably because Outlook has some
>> locked
>> messages, then release
>> some of them, etc.
>> After a little while, I can see that some of the messages have been
>> closed,
>> cause I can now preview
>> the same message I couldn't a little while before, in the preview
>> pane.
>> I tried using the .Close method, which results in no changes at all,
>> except
>> for my screen being spammed
>> by:
>> MemberType : Method
>> OverloadDefinitions : {void Close (OlInspectorClose)}
>> TypeNameOfValue : System.Management.Automation.PSMethod
>> Value : void Close (OlInspectorClose)
>> Name : Close
>> IsInstance : True
>> Best Regards,
>> Jacob Saaby Nielsen
>> http://www.pipforhelvede.net
>> gmail: jacob DOT saaby
>> hotmail (IM/LinkedIN/Facebook): same as gmail
Quote:

>>> I just wanted to check if you get the correct number of messages,
>>> the
>>> sender
>>> email address is not important.
>>> Anyway, do you get the same message "cannot read..." when you
>>> manually
>>> try
>>> to read the messages in Outlook?
>>> -----
>>> Shay Levi
>>> $cript Fanatic
>>> http://scriptolog.blogspot.com
>>>> Hey Shay,
>>>>
>>>> problem is - all mails sent to me, are from "Systemadministrator".
>>>> So
>>>> I would
>>>> get nowhere from doing that.
>>>> The e-mail address I need to extract is listed in the body of the
>>>> e-mail.
>>>> Anyway - only property I can even remotely relate to the sender,
>>>> would
>>>> be the userproperties property.
>>>> Or is there some other property I should go for ?
>>>> Best Regards,
>>>> Jacob Saaby Nielsen
>>>> http://www.pipforhelvede.net
>>>> gmail: jacob DOT saaby
>>>> hotmail (IM/LinkedIN/Facebook): same as gmail
>>>>> Can you try to list email senders only (don't process the body) ?
>>>>> How many do you get?
>>>>>
>>>>> -----
>>>>> Shay Levi
>>>>> $cript Fanatic
>>>>> http://scriptolog.blogspot.com
>>>>>> Hey guys,
>>>>>>
>>>>>> I'm doing this script, and as such it works ok. However, the
>>>>>> script
>>>>>> is
>>>>>> counting
>>>>>> 766 mails that match the subject filter,
>>>>>> and I'm only getting 247 e-mail addresses from the script.
>>>>>> So I poked around a bit, and noticed that a lot of the e-mail
>>>>>> messages
>>>>>> has
>>>>>> a "This item cannot be displayed in the reading
>>>>>> pane". Seems when I run the script, Outlook reaches a point where
>>>>>> I
>>>>>> have
>>>>>> too many open messages at the same time.
>>>>>> Anybody got a take on how to get around this ?
>>>>>> I'm pasting my sourcecode so you have the option of commenting my
>>>>>> code, what
>>>>>> to improve, or specifically how to get
>>>>>> around this "problem".
>>>>>> #
>>>>>> =================================================================
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> ==========================================
>>>>>> #
>>>>>> # Script Information
>>>>>> #
>>>>>> # Title: NDRs.ps1
>>>>>> # Author: Jacob Saaby Nielsen ()
>>>>>> # Originally created: 06-02-2008 - 11:25:18
>>>>>> # Description: Extracts e-mail addresses and error-codes from
>>>>>> NDR
>>>>>> mails,
>>>>>> from a folder in Outlook
>>>>>> #
>>>>>> #
>>>>>> =================================================================
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> ==========================================
>>>>>> #-------- Configurable Settings --------
>>>>>> # $subjectFilter needs to contain the word/words of the subject
>>>>>> you
>>>>>> want
>>>>>> to match
>>>>>> $subjectFilter = "User Forum"
>>>>>> # $NDRFolderName is the name of the folder in which you store the
>>>>>> NDRs. Folder
>>>>>> needs to be at the folderlevel just beneath Inbox
>>>>>> $NDRFolderName = "Undelivered"
>>>>>> # $NDRResultsFolder is the folder in which you want your results
>>>>>> file
>>>>>> located.
>>>>>> End with a backslash.
>>>>>> $NDRResultsFolder = "c:\"
>>>>>> # $NDRResultsFile is the name of the results file
>>>>>> $NDRResultsFile = "ndr-list.csv"
>>>>>> #-------- Non-configurable Settings - Do not change anything
>>>>>> after
>>>>>> this line --------
>>>>>> # Instantiating Outlook etc.
>>>>>> $olFolderInbox = 6;
>>>>>> $outlook = New-Object -com outlook.application;
>>>>>> $ns = $outlook.GetNameSpace("MAPI");
>>>>>> $NDRs =
>>>>>> $ns.GetDefaultFolder($olFolderInbox).Folders.Item("$NDRFolderName
>>>>>> "
>>>>>> )
>>>>>> CLS
>>>>>> Write-Host 'Getting total number of eAlert mails...'
>>>>>> # Filter out all the files that are not meeting your subject
>>>>>> filter
>>>>>> $eAlertMails = $NDRs.Items | where {$_.Subject -match
>>>>>> $subjectFilter}
>>>>>> # Returns e-mail address from the message body, based on a
>>>>>> regular
>>>>>> expression
>>>>>> function get-Email([string]$MailBody)
>>>>>> {
>>>>>> $Regex = [regex]
>>>>>> "([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|((
>>>>>> [
>>>>>> a
>>>>>> -
>>>>>> z
>>>>>> A
>>>>>> -Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})"
>>>>>> $Match = $Regex.Match($MailBody)
>>>>>> return $Match.Value
>>>>>> }
>>>>>> [int]$MailCounter = 1
>>>>>> foreach ($eAlertMail in $eAlertMails.Items)
>>>>>> {
>>>>>> # Create and update the progress bar
>>>>>> $status = "Processing mail {0} of {1}" -f $MailCounter,
>>>>>> $eAlertMails.Count
>>>>>> Write-Progress $status -PercentComplete ((100 /
>>>>>> $eAlertMails.Count)
>>>>>> *
>>>>>> $MailCounter
>>>>>> ) -Activity "Processing e-mails" -ID 1
>>>>>> # Add the string to the results file
>>>>>> Add-Content -path $NDRResultsFolder$NDRResultsFile -value
>>>>>> (get-Email
>>>>>> $eAlertMail.Body)
>>>>>> # Increment $MailCounter
>>>>>> $MailCounter++
>>>>>> }
>>>>>> Best Regards,
>>>>>> Jacob Saaby Nielsen
>>>>>> http://www.pipforhelvede.net
>>>>>> gmail: jacob DOT saaby
>>>>>> hotmail (IM/LinkedIN/Facebook): same as gmail

My System SpecsSystem Spec
Old 02-26-2008   #13 (permalink)
Jacob Saaby Nielsen


 
 

Re: Reading Outlook Messages

Hey Shay,

found this too, on Experts-Exchange:

http://www.experts-exchange.com/Soft...tml#discussion

Seems it's not my script as such, it's an issue with Outlook 2007 / Office
2007. One guy went back to Office 2003,
and the problem disappeared.

Best Regards,
Jacob Saaby Nielsen

http://www.pipforhelvede.net
gmail: jacob DOT saaby
hotmail (IM/LinkedIN/Facebook): same as gmail
Quote:

> I'm not sure.. can you try piping items instead of using the forach
> loop, as in:
>
> $eAlertMails.Items | foreach {...}
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
Quote:

>> Hey Shay,
>>
>> yeah that's how I originally found out, by poking around the message
>> list
>> in Outlook.
>> I don't really see anything when my script runs, other than it goes
>> from
>> "ok, it's processing something",
>> to "ok, now it's just skipping through everything".
>> I can also see it in the generated text file. Suddenly there are gaps
>> of
>> 2-3 lines in Excel. Then some
>> more e-mail addresses. Which is probably because Outlook has some
>> locked
>> messages, then release
>> some of them, etc.
>> After a little while, I can see that some of the messages have been
>> closed,
>> cause I can now preview
>> the same message I couldn't a little while before, in the preview
>> pane.
>> I tried using the .Close method, which results in no changes at all,
>> except
>> for my screen being spammed
>> by:
>> MemberType : Method
>> OverloadDefinitions : {void Close (OlInspectorClose)}
>> TypeNameOfValue : System.Management.Automation.PSMethod
>> Value : void Close (OlInspectorClose)
>> Name : Close
>> IsInstance : True
>> Best Regards,
>> Jacob Saaby Nielsen
>> http://www.pipforhelvede.net
>> gmail: jacob DOT saaby
>> hotmail (IM/LinkedIN/Facebook): same as gmail
Quote:

>>> I just wanted to check if you get the correct number of messages,
>>> the
>>> sender
>>> email address is not important.
>>> Anyway, do you get the same message "cannot read..." when you
>>> manually
>>> try
>>> to read the messages in Outlook?
>>> -----
>>> Shay Levi
>>> $cript Fanatic
>>> http://scriptolog.blogspot.com
>>>> Hey Shay,
>>>>
>>>> problem is - all mails sent to me, are from "Systemadministrator".
>>>> So
>>>> I would
>>>> get nowhere from doing that.
>>>> The e-mail address I need to extract is listed in the body of the
>>>> e-mail.
>>>> Anyway - only property I can even remotely relate to the sender,
>>>> would
>>>> be the userproperties property.
>>>> Or is there some other property I should go for ?
>>>> Best Regards,
>>>> Jacob Saaby Nielsen
>>>> http://www.pipforhelvede.net
>>>> gmail: jacob DOT saaby
>>>> hotmail (IM/LinkedIN/Facebook): same as gmail
>>>>> Can you try to list email senders only (don't process the body) ?
>>>>> How many do you get?
>>>>>
>>>>> -----
>>>>> Shay Levi
>>>>> $cript Fanatic
>>>>> http://scriptolog.blogspot.com
>>>>>> Hey guys,
>>>>>>
>>>>>> I'm doing this script, and as such it works ok. However, the
>>>>>> script
>>>>>> is
>>>>>> counting
>>>>>> 766 mails that match the subject filter,
>>>>>> and I'm only getting 247 e-mail addresses from the script.
>>>>>> So I poked around a bit, and noticed that a lot of the e-mail
>>>>>> messages
>>>>>> has
>>>>>> a "This item cannot be displayed in the reading
>>>>>> pane". Seems when I run the script, Outlook reaches a point where
>>>>>> I
>>>>>> have
>>>>>> too many open messages at the same time.
>>>>>> Anybody got a take on how to get around this ?
>>>>>> I'm pasting my sourcecode so you have the option of commenting my
>>>>>> code, what
>>>>>> to improve, or specifically how to get
>>>>>> around this "problem".
>>>>>> #
>>>>>> =================================================================
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> ==========================================
>>>>>> #
>>>>>> # Script Information
>>>>>> #
>>>>>> # Title: NDRs.ps1
>>>>>> # Author: Jacob Saaby Nielsen ()
>>>>>> # Originally created: 06-02-2008 - 11:25:18
>>>>>> # Description: Extracts e-mail addresses and error-codes from
>>>>>> NDR
>>>>>> mails,
>>>>>> from a folder in Outlook
>>>>>> #
>>>>>> #
>>>>>> =================================================================
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> ==========================================
>>>>>> #-------- Configurable Settings --------
>>>>>> # $subjectFilter needs to contain the word/words of the subject
>>>>>> you
>>>>>> want
>>>>>> to match
>>>>>> $subjectFilter = "User Forum"
>>>>>> # $NDRFolderName is the name of the folder in which you store the
>>>>>> NDRs. Folder
>>>>>> needs to be at the folderlevel just beneath Inbox
>>>>>> $NDRFolderName = "Undelivered"
>>>>>> # $NDRResultsFolder is the folder in which you want your results
>>>>>> file
>>>>>> located.
>>>>>> End with a backslash.
>>>>>> $NDRResultsFolder = "c:\"
>>>>>> # $NDRResultsFile is the name of the results file
>>>>>> $NDRResultsFile = "ndr-list.csv"
>>>>>> #-------- Non-configurable Settings - Do not change anything
>>>>>> after
>>>>>> this line --------
>>>>>> # Instantiating Outlook etc.
>>>>>> $olFolderInbox = 6;
>>>>>> $outlook = New-Object -com outlook.application;
>>>>>> $ns = $outlook.GetNameSpace("MAPI");
>>>>>> $NDRs =
>>>>>> $ns.GetDefaultFolder($olFolderInbox).Folders.Item("$NDRFolderName
>>>>>> "
>>>>>> )
>>>>>> CLS
>>>>>> Write-Host 'Getting total number of eAlert mails...'
>>>>>> # Filter out all the files that are not meeting your subject
>>>>>> filter
>>>>>> $eAlertMails = $NDRs.Items | where {$_.Subject -match
>>>>>> $subjectFilter}
>>>>>> # Returns e-mail address from the message body, based on a
>>>>>> regular
>>>>>> expression
>>>>>> function get-Email([string]$MailBody)
>>>>>> {
>>>>>> $Regex = [regex]
>>>>>> "([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|((
>>>>>> [
>>>>>> a
>>>>>> -
>>>>>> z
>>>>>> A
>>>>>> -Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})"
>>>>>> $Match = $Regex.Match($MailBody)
>>>>>> return $Match.Value
>>>>>> }
>>>>>> [int]$MailCounter = 1
>>>>>> foreach ($eAlertMail in $eAlertMails.Items)
>>>>>> {
>>>>>> # Create and update the progress bar
>>>>>> $status = "Processing mail {0} of {1}" -f $MailCounter,
>>>>>> $eAlertMails.Count
>>>>>> Write-Progress $status -PercentComplete ((100 /
>>>>>> $eAlertMails.Count)
>>>>>> *
>>>>>> $MailCounter
>>>>>> ) -Activity "Processing e-mails" -ID 1
>>>>>> # Add the string to the results file
>>>>>> Add-Content -path $NDRResultsFolder$NDRResultsFile -value
>>>>>> (get-Email
>>>>>> $eAlertMail.Body)
>>>>>> # Increment $MailCounter
>>>>>> $MailCounter++
>>>>>> }
>>>>>> Best Regards,
>>>>>> Jacob Saaby Nielsen
>>>>>> http://www.pipforhelvede.net
>>>>>> gmail: jacob DOT saaby
>>>>>> hotmail (IM/LinkedIN/Facebook): same as gmail

My System SpecsSystem Spec
Old 02-26-2008   #14 (permalink)
Shay Levi


 
 

Re: Reading Outlook Messages

I can see what you mean but your problem happens locally on your Outlook,
I don't think it relates.
As I said, I was anble to run it on a local folder contains more than 3500
items without a problem.

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Hey Shay,
>
> I found this:
> http://www.microsoft.com/communities...fault.aspx?dg=
> microsoft.public.outlook.program_vba&tid=63338904-8dab-4fec-8459-5eec1
> 12828fc&cat=&lang=&cr=&sloc=&p=1
>
> Question is:
>
> - Can I invoke the garbage collector myself, and if so - how ?
>
> Cause if that link has anything to it, I should be able to close the
> messages, and then GC, let's say every 100 messages.
>
> Best Regards,
> Jacob Saaby Nielsen
> http://www.pipforhelvede.net
> gmail: jacob DOT saaby
> hotmail (IM/LinkedIN/Facebook): same as gmail
Quote:

>> I'm not sure.. can you try piping items instead of using the forach
>> loop, as in:
>>
>> $eAlertMails.Items | foreach {...}
>>
>> -----
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
Quote:

>>> Hey Shay,
>>>
>>> yeah that's how I originally found out, by poking around the message
>>> list
>>> in Outlook.
>>> I don't really see anything when my script runs, other than it goes
>>> from
>>> "ok, it's processing something",
>>> to "ok, now it's just skipping through everything".
>>> I can also see it in the generated text file. Suddenly there are
>>> gaps
>>> of
>>> 2-3 lines in Excel. Then some
>>> more e-mail addresses. Which is probably because Outlook has some
>>> locked
>>> messages, then release
>>> some of them, etc.
>>> After a little while, I can see that some of the messages have been
>>> closed,
>>> cause I can now preview
>>> the same message I couldn't a little while before, in the preview
>>> pane.
>>> I tried using the .Close method, which results in no changes at all,
>>> except
>>> for my screen being spammed
>>> by:
>>> MemberType : Method
>>> OverloadDefinitions : {void Close (OlInspectorClose)}
>>> TypeNameOfValue : System.Management.Automation.PSMethod
>>> Value : void Close (OlInspectorClose)
>>> Name : Close
>>> IsInstance : True
>>> Best Regards,
>>> Jacob Saaby Nielsen
>>> http://www.pipforhelvede.net
>>> gmail: jacob DOT saaby
>>> hotmail (IM/LinkedIN/Facebook): same as gmail
>>>> I just wanted to check if you get the correct number of messages,
>>>> the
>>>> sender
>>>> email address is not important.
>>>> Anyway, do you get the same message "cannot read..." when you
>>>> manually
>>>> try
>>>> to read the messages in Outlook?
>>>> -----
>>>> Shay Levi
>>>> $cript Fanatic
>>>> http://scriptolog.blogspot.com
>>>>> Hey Shay,
>>>>>
>>>>> problem is - all mails sent to me, are from "Systemadministrator".
>>>>> So
>>>>> I would
>>>>> get nowhere from doing that.
>>>>> The e-mail address I need to extract is listed in the body of the
>>>>> e-mail.
>>>>> Anyway - only property I can even remotely relate to the sender,
>>>>> would
>>>>> be the userproperties property.
>>>>> Or is there some other property I should go for ?
>>>>> Best Regards,
>>>>> Jacob Saaby Nielsen
>>>>> http://www.pipforhelvede.net
>>>>> gmail: jacob DOT saaby
>>>>> hotmail (IM/LinkedIN/Facebook): same as gmail
>>>>>> Can you try to list email senders only (don't process the body) ?
>>>>>> How many do you get?
>>>>>>
>>>>>> -----
>>>>>> Shay Levi
>>>>>> $cript Fanatic
>>>>>> http://scriptolog.blogspot.com
>>>>>>> Hey guys,
>>>>>>>
>>>>>>> I'm doing this script, and as such it works ok. However, the
>>>>>>> script
>>>>>>> is
>>>>>>> counting
>>>>>>> 766 mails that match the subject filter,
>>>>>>> and I'm only getting 247 e-mail addresses from the script.
>>>>>>> So I poked around a bit, and noticed that a lot of the e-mail
>>>>>>> messages
>>>>>>> has
>>>>>>> a "This item cannot be displayed in the reading
>>>>>>> pane". Seems when I run the script, Outlook reaches a point
>>>>>>> where
>>>>>>> I
>>>>>>> have
>>>>>>> too many open messages at the same time.
>>>>>>> Anybody got a take on how to get around this ?
>>>>>>> I'm pasting my sourcecode so you have the option of commenting
>>>>>>> my
>>>>>>> code, what
>>>>>>> to improve, or specifically how to get
>>>>>>> around this "problem".
>>>>>>> #
>>>>>>> ================================================================
>>>>>>> =
>>>>>>> =
>>>>>>> =
>>>>>>> =
>>>>>>> =
>>>>>>> =
>>>>>>> ==========================================
>>>>>>> #
>>>>>>> # Script Information
>>>>>>> #
>>>>>>> # Title: NDRs.ps1
>>>>>>> # Author: Jacob Saaby Nielsen ()
>>>>>>> # Originally created: 06-02-2008 - 11:25:18
>>>>>>> # Description: Extracts e-mail addresses and error-codes from
>>>>>>> NDR
>>>>>>> mails,
>>>>>>> from a folder in Outlook
>>>>>>> #
>>>>>>> #
>>>>>>> ================================================================
>>>>>>> =
>>>>>>> =
>>>>>>> =
>>>>>>> =
>>>>>>> =
>>>>>>> =
>>>>>>> ==========================================
>>>>>>> #-------- Configurable Settings --------
>>>>>>> # $subjectFilter needs to contain the word/words of the subject
>>>>>>> you
>>>>>>> want
>>>>>>> to match
>>>>>>> $subjectFilter = "User Forum"
>>>>>>> # $NDRFolderName is the name of the folder in which you store
>>>>>>> the
>>>>>>> NDRs. Folder
>>>>>>> needs to be at the folderlevel just beneath Inbox
>>>>>>> $NDRFolderName = "Undelivered"
>>>>>>> # $NDRResultsFolder is the folder in which you want your results
>>>>>>> file
>>>>>>> located.
>>>>>>> End with a backslash.
>>>>>>> $NDRResultsFolder = "c:\"
>>>>>>> # $NDRResultsFile is the name of the results file
>>>>>>> $NDRResultsFile = "ndr-list.csv"
>>>>>>> #-------- Non-configurable Settings - Do not change anything
>>>>>>> after
>>>>>>> this line --------
>>>>>>> # Instantiating Outlook etc.
>>>>>>> $olFolderInbox = 6;
>>>>>>> $outlook = New-Object -com outlook.application;
>>>>>>> $ns = $outlook.GetNameSpace("MAPI");
>>>>>>> $NDRs =
>>>>>>> $ns.GetDefaultFolder($olFolderInbox).Folders.Item("$NDRFolderNam
>>>>>>> e
>>>>>>> "
>>>>>>> )
>>>>>>> CLS
>>>>>>> Write-Host 'Getting total number of eAlert mails...'
>>>>>>> # Filter out all the files that are not meeting your subject
>>>>>>> filter
>>>>>>> $eAlertMails = $NDRs.Items | where {$_.Subject -match
>>>>>>> $subjectFilter}
>>>>>>> # Returns e-mail address from the message body, based on a
>>>>>>> regular
>>>>>>> expression
>>>>>>> function get-Email([string]$MailBody)
>>>>>>> {
>>>>>>> $Regex = [regex]
>>>>>>> "([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(
>>>>>>> (
>>>>>>> [
>>>>>>> a
>>>>>>> -
>>>>>>> z
>>>>>>> A
>>>>>>> -Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})"
>>>>>>> $Match = $Regex.Match($MailBody)
>>>>>>> return $Match.Value
>>>>>>> }
>>>>>>> [int]$MailCounter = 1
>>>>>>> foreach ($eAlertMail in $eAlertMails.Items)
>>>>>>> {
>>>>>>> # Create and update the progress bar
>>>>>>> $status = "Processing mail {0} of {1}" -f $MailCounter,
>>>>>>> $eAlertMails.Count
>>>>>>> Write-Progress $status -PercentComplete ((100 /
>>>>>>> $eAlertMails.Count)
>>>>>>> *
>>>>>>> $MailCounter
>>>>>>> ) -Activity "Processing e-mails" -ID 1
>>>>>>> # Add the string to the results file
>>>>>>> Add-Content -path $NDRResultsFolder$NDRResultsFile -value
>>>>>>> (get-Email
>>>>>>> $eAlertMail.Body)
>>>>>>> # Increment $MailCounter
>>>>>>> $MailCounter++
>>>>>>> }
>>>>>>> Best Regards,
>>>>>>> Jacob Saaby Nielsen
>>>>>>> http://www.pipforhelvede.net
>>>>>>> gmail: jacob DOT saaby
>>>>>>> hotmail (IM/LinkedIN/Facebook): same as gmail

My System SpecsSystem Spec
Old 02-26-2008   #15 (permalink)
Shay Levi


 
 

Re: Reading Outlook Messages


Can you try running your code on another Outlook folder?

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> I ran your code on my outlook where my directory contains 3552 items,
> this is the test command I've used:
>
> $ndrs.items | foreach {$_.body -match "Shay"}
>
> All items processed successfully. BTW, What Outlook version? I'm on
> 2007.
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
Quote:

>> Hey Shay,
>>
>> one more thing: When I quit Outlook, I get a million (or rather, I'm
>> probably
>> getting
>> precisely 247, but I haven't stuck it out and counted - just pressed
>> cancel
>> ),
>> dialogues if I want to save the changes. Which is proably the
>> messages
>> I
>> opened
>> with the script.
>> Best Regards,
>> Jacob Saaby Nielsen
>> http://www.pipforhelvede.net
>> gmail: jacob DOT saaby
>> hotmail (IM/LinkedIN/Facebook): same as gmail
Quote:

>>> I just wanted to check if you get the correct number of messages,
>>> the
>>> sender
>>> email address is not important.
>>> Anyway, do you get the same message "cannot read..." when you
>>> manually
>>> try
>>> to read the messages in Outlook?
>>> -----
>>> Shay Levi
>>> $cript Fanatic
>>> http://scriptolog.blogspot.com
>>>> Hey Shay,
>>>>
>>>> problem is - all mails sent to me, are from "Systemadministrator".
>>>> So
>>>> I would
>>>> get nowhere from doing that.
>>>> The e-mail address I need to extract is listed in the body of the
>>>> e-mail.
>>>> Anyway - only property I can even remotely relate to the sender,
>>>> would
>>>> be the userproperties property.
>>>> Or is there some other property I should go for ?
>>>> Best Regards,
>>>> Jacob Saaby Nielsen
>>>> http://www.pipforhelvede.net
>>>> gmail: jacob DOT saaby
>>>> hotmail (IM/LinkedIN/Facebook): same as gmail
>>>>> Can you try to list email senders only (don't process the body) ?
>>>>> How many do you get?
>>>>>
>>>>> -----
>>>>> Shay Levi
>>>>> $cript Fanatic
>>>>> http://scriptolog.blogspot.com
>>>>>> Hey guys,
>>>>>>
>>>>>> I'm doing this script, and as such it works ok. However, the
>>>>>> script
>>>>>> is
>>>>>> counting
>>>>>> 766 mails that match the subject filter,
>>>>>> and I'm only getting 247 e-mail addresses from the script.
>>>>>> So I poked around a bit, and noticed that a lot of the e-mail
>>>>>> messages
>>>>>> has
>>>>>> a "This item cannot be displayed in the reading
>>>>>> pane". Seems when I run the script, Outlook reaches a point where
>>>>>> I
>>>>>> have
>>>>>> too many open messages at the same time.
>>>>>> Anybody got a take on how to get around this ?
>>>>>> I'm pasting my sourcecode so you have the option of commenting my
>>>>>> code, what
>>>>>> to improve, or specifically how to get
>>>>>> around this "problem".
>>>>>> #
>>>>>> =================================================================
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> ==========================================
>>>>>> #
>>>>>> # Script Information
>>>>>> #
>>>>>> # Title: NDRs.ps1
>>>>>> # Author: Jacob Saaby Nielsen ()
>>>>>> # Originally created: 06-02-2008 - 11:25:18
>>>>>> # Description: Extracts e-mail addresses and error-codes from
>>>>>> NDR
>>>>>> mails,
>>>>>> from a folder in Outlook
>>>>>> #
>>>>>> #
>>>>>> =================================================================
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> =
>>>>>> ==========================================
>>>>>> #-------- Configurable Settings --------
>>>>>> # $subjectFilter needs to contain the word/words of the subject
>>>>>> you
>>>>>> want
>>>>>> to match
>>>>>> $subjectFilter = "User Forum"
>>>>>> # $NDRFolderName is the name of the folder in which you store the
>>>>>> NDRs. Folder
>>>>>> needs to be at the folderlevel just beneath Inbox
>>>>>> $NDRFolderName = "Undelivered"
>>>>>> # $NDRResultsFolder is the folder in which you want your results
>>>>>> file
>>>>>> located.
>>>>>> End with a backslash.
>>>>>> $NDRResultsFolder = "c:\"
>>>>>> # $NDRResultsFile is the name of the results file
>>>>>> $NDRResultsFile = "ndr-list.csv"
>>>>>> #-------- Non-configurable Settings - Do not change anything
>>>>>> after
>>>>>> this line --------
>>>>>> # Instantiating Outlook etc.
>>>>>> $olFolderInbox = 6;
>>>>>> $outlook = New-Object -com outlook.application;
>>>>>> $ns = $outlook.GetNameSpace("MAPI");
>>>>>> $NDRs =
>>>>>> $ns.GetDefaultFolder($olFolderInbox).Folders.Item("$NDRFolderName
>>>>>> "
>>>>>> )
>>>>>> CLS
>>>>>> Write-Host 'Getting total number of eAlert mails...'
>>>>>> # Filter out all the files that are not meeting your subject
>>>>>> filter
>>>>>> $eAlertMails = $NDRs.Items | where {$_.Subject -match
>>>>>> $subjectFilter}
>>>>>> # Returns e-mail address from the message body, based on a
>>>>>> regular
>>>>>> expression
>>>>>> function get-Email([string]$MailBody)
>>>>>> {
>>>>>> $Regex = [regex]
>>>>>> "([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|((
>>>>>> [
>>>>>> a
>>>>>> -
>>>>>> z
>>>>>> A
>>>>>> -Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})"
>>>>>> $Match = $Regex.Match($MailBody)
>>>>>> return $Match.Value
>>>>>> }
>>>>>> [int]$MailCounter = 1
>>>>>> foreach ($eAlertMail in $eAlertMails.Items)
>>>>>> {
>>>>>> # Create and update the progress bar
>>>>>> $status = "Processing mail {0} of {1}" -f $MailCounter,
>>>>>> $eAlertMails.Count
>>>>>> Write-Progress $status -PercentComplete ((100 /
>>>>>> $eAlertMails.Count)
>>>>>> *
>>>>>> $MailCounter
>>>>>> ) -Activity "Processing e-mails" -ID 1
>>>>>> # Add the string to the results file
>>>>>> Add-Content -path $NDRResultsFolder$NDRResultsFile -value
>>>>>> (get-Email
>>>>>> $eAlertMail.Body)
>>>>>> # Increment $MailCounter
>>>>>> $MailCounter++
>>>>>> }
>>>>>> Best Regards,
>>>>>> Jacob Saaby Nielsen
>>>>>> http://www.pipforhelvede.net
>>>>>> gmail: jacob DOT saaby
>>>>>> hotmail (IM/LinkedIN/Facebook): same as gmail

My System SpecsSystem Spec
Old 02-26-2008   #16 (permalink)
Jacob Saaby Nielsen


 
 

Re: Reading Outlook Messages

Hey Shay,

SUCCESS ! The correct solution is right here, found it after some digging
through piles of references from site to site

http://support.microsoft.com/kb/830836

No error messages, and a full list of e-mail addresses generated

Best Regards,
Jacob Saaby Nielsen

http://www.pipforhelvede.net
gmail: jacob DOT saaby
hotmail (IM/LinkedIN/Facebook): same as gmail
Quote:

> I can see what you mean but your problem happens locally on your
> Outlook,
> I don't think it relates.
> As I said, I was anble to run it on a local folder contains more than
> 3500
> items without a problem.
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
Quote:

>> Hey Shay,
>>
>> I found this:
>> http://www.microsoft.com/communities...efault.aspx?dg
>> =
>> microsoft.public.outlook.program_vba&tid=63338904-8dab-4fec-8459-5eec
>> 1 12828fc&cat=&lang=&cr=&sloc=&p=1
>>
>> Question is:
>>
>> - Can I invoke the garbage collector myself, and if so - how ?
>>
>> Cause if that link has anything to it, I should be able to close the
>> messages, and then GC, let's say every 100 messages.
>>
>> Best Regards,
>> Jacob Saaby Nielsen
>> http://www.pipforhelvede.net
>> gmail: jacob DOT saaby
>> hotmail (IM/LinkedIN/Facebook): same as gmail
Quote:

>>> I'm not sure.. can you try piping items instead of using the forach
>>> loop, as in:
>>>
>>> $eAlertMails.Items | foreach {...}
>>>
>>> -----
>>> Shay Levi
>>> $cript Fanatic
>>> http://scriptolog.blogspot.com
>>>> Hey Shay,
>>>>
>>>> yeah that's how I originally found out, by poking around the
>>>> message
>>>> list
>>>> in Outlook.
>>>> I don't really see anything when my script runs, other than it goes
>>>> from
>>>> "ok, it's processing something",
>>>> to "ok, now it's just skipping through everything".
>>>> I can also see it in the generated text file. Suddenly there are
>>>> gaps
>>>> of
>>>> 2-3 lines in Excel. Then some
>>>> more e-mail addresses. Which is probably because Outlook has some
>>>> locked
>>>> messages, then release
>>>> some of them, etc.
>>>> After a little while, I can see that some of the messages have been
>>>> closed,
>>>> cause I can now preview
>>>> the same message I couldn't a little while before, in the preview
>>>> pane.
>>>> I tried using the .Close method, which results in no changes at
>>>> all,
>>>> except
>>>> for my screen being spammed
>>>> by:
>>>> MemberType : Method
>>>> OverloadDefinitions : {void Close (OlInspectorClose)}
>>>> TypeNameOfValue : System.Management.Automation.PSMethod
>>>> Value : void Close (OlInspectorClose)
>>>> Name : Close
>>>> IsInstance : True
>>>> Best Regards,
>>>> Jacob Saaby Nielsen
>>>> http://www.pipforhelvede.net
>>>> gmail: jacob DOT saaby
>>>> hotmail (IM/LinkedIN/Facebook): same as gmail
>>>>> I just wanted to check if you get the correct number of messages,
>>>>> the
>>>>> sender
>>>>> email address is not important.
>>>>> Anyway, do you get the same message "cannot read..." when you
>>>>> manually
>>>>> try
>>>>> to read the messages in Outlook?
>>>>> -----
>>>>> Shay Levi
>>>>> $cript Fanatic
>>>>> http://scriptolog.blogspot.com
>>>>>> Hey Shay,
>>>>>>
>>>>>> problem is - all mails sent to me, are from
>>>>>> "Systemadministrator".
>>>>>> So
>>>>>> I would
>>>>>> get nowhere from doing that.
>>>>>> The e-mail address I need to extract is listed in the body of the
>>>>>> e-mail.
>>>>>> Anyway - only property I can even remotely relate to the sender,
>>>>>> would
>>>>>> be the userproperties property.
>>>>>> Or is there some other property I should go for ?
>>>>>> Best Regards,
>>>>>> Jacob Saaby Nielsen
>>>>>> http://www.pipforhelvede.net
>>>>>> gmail: jacob DOT saaby
>>>>>> hotmail (IM/LinkedIN/Facebook): same as gmail
>>>>>>> Can you try to list email senders only (don't process the body)
>>>>>>> ? How many do you get?
>>>>>>>
>>>>>>> -----
>>>>>>> Shay Levi
>>>>>>> $cript Fanatic
>>>>>>> http://scriptolog.blogspot.com
>>>>>>>> Hey guys,
>>>>>>>>
>>>>>>>> I'm doing this script, and as such it works ok. However, the
>>>>>>>> script
>>>>>>>> is
>>>>>>>> counting
>>>>>>>> 766 mails that match the subject filter,
>>>>>>>> and I'm only getting 247 e-mail addresses from the script.
>>>>>>>> So I poked around a bit, and noticed that a lot of the e-mail
>>>>>>>> messages
>>>>>>>> has
>>>>>>>> a "This item cannot be displayed in the reading
>>>>>>>> pane". Seems when I run the script, Outlook reaches a point
>>>>>>>> where
>>>>>>>> I
>>>>>>>> have
>>>>>>>> too many open messages at the same time.
>>>>>>>> Anybody got a take on how to get around this ?
>>>>>>>> I'm pasting my sourcecode so you have the option of commenting
>>>>>>>> my
>>>>>>>> code, what
>>>>>>>> to improve, or specifically how to get
>>>>>>>> around this "problem".
>>>>>>>> #
>>>>>>>> ===============================================================
>>>>>>>> =
>>>>>>>> =
>>>>>>>> =
>>>>>>>> =
>>>>>>>> =
>>>>>>>> =
>>>>>>>> =
>>>>>>>> ==========================================
>>>>>>>> #
>>>>>>>> # Script Information
>>>>>>>> #
>>>>>>>> # Title: NDRs.ps1
>>>>>>>> # Author: Jacob Saaby Nielsen ()
>>>>>>>> # Originally created: 06-02-2008 - 11:25:18
>>>>>>>> # Description: Extracts e-mail addresses and error-codes from
>>>>>>>> NDR
>>>>>>>> mails,
>>>>>>>> from a folder in Outlook
>>>>>>>> #
>>>>>>>> #
>>>>>>>> ===============================================================
>>>>>>>> =
>>>>>>>> =
>>>>>>>> =
>>>>>>>> =
>>>>>>>> =
>>>>>>>> =
>>>>>>>> =
>>>>>>>> ==========================================
>>>>>>>> #-------- Configurable Settings --------
>>>>>>>> # $subjectFilter needs to contain the word/words of the subject
>>>>>>>> you
>>>>>>>> want
>>>>>>>> to match
>>>>>>>> $subjectFilter = "User Forum"
>>>>>>>> # $NDRFolderName is the name of the folder in which you store
>>>>>>>> the
>>>>>>>> NDRs. Folder
>>>>>>>> needs to be at the folderlevel just beneath Inbox
>>>>>>>> $NDRFolderName = "Undelivered"
>>>>>>>> # $NDRResultsFolder is the folder in which you want your
>>>>>>>> results
>>>>>>>> file
>>>>>>>> located.
>>>>>>>> End with a backslash.
>>>>>>>> $NDRResultsFolder = "c:\"
>>>>>>>> # $NDRResultsFile is the name of the results file
>>>>>>>> $NDRResultsFile = "ndr-list.csv"
>>>>>>>> #-------- Non-configurable Settings - Do not change anything
>>>>>>>> after
>>>>>>>> this line --------
>>>>>>>> # Instantiating Outlook etc.
>>>>>>>> $olFolderInbox = 6;
>>>>>>>> $outlook = New-Object -com outlook.application;
>>>>>>>> $ns = $outlook.GetNameSpace("MAPI");
>>>>>>>> $NDRs =
>>>>>>>> $ns.GetDefaultFolder($olFolderInbox).Folders.Item("$NDRFolderNa
>>>>>>>> m
>>>>>>>> e
>>>>>>>> "
>>>>>>>> )
>>>>>>>> CLS
>>>>>>>> Write-Host 'Getting total number of eAlert mails...'
>>>>>>>> # Filter out all the files that are not meeting your subject
>>>>>>>> filter
>>>>>>>> $eAlertMails = $NDRs.Items | where {$_.Subject -match
>>>>>>>> $subjectFilter}
>>>>>>>> # Returns e-mail address from the message body, based on a
>>>>>>>> regular
>>>>>>>> expression
>>>>>>>> function get-Email([string]$MailBody)
>>>>>>>> {
>>>>>>>> $Regex = [regex]
>>>>>>>> "([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|
>>>>>>>> (
>>>>>>>> (
>>>>>>>> [
>>>>>>>> a
>>>>>>>> -
>>>>>>>> z
>>>>>>>> A
>>>>>>>> -Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})"
>>>>>>>> $Match = $Regex.Match($MailBody)
>>>>>>>> return $Match.Value
>>>>>>>> }
>>>>>>>> [int]$MailCounter = 1
>>>>>>>> foreach ($eAlertMail in $eAlertMails.Items)
>>>>>>>> {
>>>>>>>> # Create and update the progress bar
>>>>>>>> $status = "Processing mail {0} of {1}" -f $MailCounter,
>>>>>>>> $eAlertMails.Count
>>>>>>>> Write-Progress $status -PercentComplete ((100 /
>>>>>>>> $eAlertMails.Count)
>>>>>>>> *
>>>>>>>> $MailCounter
>>>>>>>> ) -Activity "Processing e-mails" -ID 1
>>>>>>>> # Add the string to the results file
>>>>>>>> Add-Content -path $NDRResultsFolder$NDRResultsFile -value
>>>>>>>> (get-Email
>>>>>>>> $eAlertMail.Body)
>>>>>>>> # Increment $MailCounter
>>>>>>>> $MailCounter++
>>>>>>>> }
>>>>>>>> Best Regards,
>>>>>>>> Jacob Saaby Nielsen
>>>>>>>> http://www.pipforhelvede.net
>>>>>>>> gmail: jacob DOT saaby
>>>>>>>> hotmail (IM/LinkedIN/Facebook): same as gmail

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Reading Newsgroup Messages In OE & WLM Live Mail
Reading all Messages in a thread.............. Vista performance & maintenance
Reading messages offline Vista mail
Deleting messages while in reading pane Vista mail
reading my messages Vista mail


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46