View Single Post
Old 02-25-2008   #6 (permalink)
Jacob Saaby Nielsen


 
 

Re: Reading Outlook Messages

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
Quote:

>> 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
Quote:

>>> 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