![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Reading Outlook Messages 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-zA-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 Specs![]() |
| | #2 (permalink) |
| | Re: Reading Outlook Messages Oh sorry btw... forget about the .items in $eAlertMails.Items - that was just a test ![]() Best Regards, Jacob Saaby Nielsen http://www.pipforhelvede.net gmail: jacob DOT saaby hotmail (IM/LinkedIN/Facebook): same as gmail Quote: > 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-zA > -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 Specs![]() |
| | #3 (permalink) |
| | Re: Reading Outlook Messages 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 Quote: > 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-zA > -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 Specs![]() |
| | #4 (permalink) |
| | Re: Reading Outlook Messages 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 Quote: >> 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 Specs![]() |
| | #5 (permalink) |
| | Re: Reading Outlook Messages 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 Quote: >>> 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 Specs![]() |
| | #6 (permalink) |
| | 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 Specs![]() |
| | #7 (permalink) |
| | Re: Reading Outlook Messages 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 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 >>>> 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 Specs![]() |
| | #8 (permalink) |
| | Re: Reading Outlook Messages 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 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 Specs![]() |
| | #9 (permalink) |
| | Re: Reading Outlook Messages 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 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 >>>> 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 Specs![]() |
| | #10 (permalink) |
| | Re: Reading Outlook Messages 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 "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 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 > >>> 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 Specs![]() |
![]() |
| 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 | |||