सबसे पहले, क्षमा याचना है कि इस जबाब लगभग दो साल के बाद सवाल है, लेकिन मैं भी PowerShell का उपयोग ईमेल की जांच करना चाहते थे और इस सवाल का पाया। उम्मीद है कि मेरा कोड पावरहेल से मेरा दृष्टिकोण देखने के लिए किसी और के लिए एक संदर्भ/प्रारंभिक बिंदु के रूप में कार्य करेगा। मैं इसे और अधिक उपयोग करने के लिए इसे स्वयं बढ़ाने की योजना बना रहा हूं।
मैं पावरहेल के लिए काफी नया हूं, इसलिए मेरी स्क्रिप्ट मुख्य रूप से विभिन्न लेखों, ब्लॉग पोस्टों और स्टैक ओवरफ्लो क्यू & से फ़्रैंकस्टाइन-एड हैं, निश्चित रूप से नीचे दी गई स्क्रिप्ट में कोई अपवाद नहीं है!
क्रिस की प्रतिक्रिया के बाद, मैंने इंटरनेट के चारों ओर खुदाई की और पावरहेल के कुछ स्निपेट को एक साथ जोड़ दिया ताकि मुझे ईमेल से जानकारी के कुछ महत्वपूर्ण टुकड़े प्रदर्शित किए जा सकें।
यह किसी भी 'उचित' शैली में दुख की कमी है और मुझे यकीन है कि कोई भी पावरहेल गुरु इस पर क्रिंग करेगा। लेकिन क्या इस कोड क्या करता है
- शो EWS & PowerShell का उपयोग करने के लिए कैसे ईमेल
पढ़ने के लिए है
- पता जॉर्ज आखिरी सवाल पुन: शरीर खाली किया जा रहा है -
FindItems
विधि पूर्ण मेल आइटम वापस नहीं करता है, तो आप आपको आवश्यक अतिरिक्त जानकारी प्राप्त करने के लिए एक और राउंड-ट्रिप करना होगा।
- आप अपने वर्तमान क्रेडेंशियल्स
- आवश्यकता का उपयोग कर हटाने EWS इंस्टॉल करने से उपयोगकर्ता नाम/पासवर्ड/डोमेन का उपयोग करने के लिए बस एमएसआई निकालने और dll
उपयोग करने के लिए संदर्भ के लिए आवश्यकता को दूर ..
ईडब्ल्यूएस from here डाउनलोड करें, फिर कहीं निकालें, उदाहरण के लिए
msiexec /a C:\Path\To\Downloads\EwsManagedApi.msi /qb TARGETDIR=C:\Progs\EwsManagedApi
तो डॉट स्रोत है, उदा का उपयोग कर इस स्क्रिप्ट फोन
. C:\Path\To\Script\Outlook_ReadInbox.ps1
जो आप स्क्रिप्ट से वस्तुओं/चर संदर्भ के लिए के बाद यह मार डाला गया है की अनुमति देता है
।
कोड में सीमित टिप्पणियां हैं, साथ ही अंत में कुछ लिंक हैं, जिन्हें मैंने स्क्रिप्ट को एक साथ जोड़ते समय संदर्भित किया था।
यहां पहले 5 ईमेल में पढ़ने के लिए कोड का मेरा अल्फा ड्राफ्ट है, यह दिखाएं कि क्या पढ़ा/अपठित है या सफेद निकाय के साथ एक पंक्ति पर ईमेल बॉडी के पहले 100 अक्षर दिखाएं।
# work with exchange server to retrieve messages
# see this SO answer: http://stackoverflow.com/a/4866894
# call this script using dot-source (see http://technet.microsoft.com/en-us/library/ee176949.aspx)
# to allow continued use of the objects, specifically, reading our inbox
# e.g...
# . C:\Path\To\Script\Outlook_ReadInbox.ps1
# replace with your email address
$email = "[email protected]"
# only need to populate these if you're impersonating...
$username = "YOUR_USER_NAME"
$password = "YOUR_LAN_PASSWORD"
$domain = "YOUR_DOMAIN"
# to allow us to write multi-coloured lines
# see http://stackoverflow.com/a/2688572
# usage: Write-Color -Text Red,White,Blue -Color Red,White,Blue
# usage: Write-Color Red,White,Blue Red,White,Blue
function Write-Color([String[]]$Text, [ConsoleColor[]]$Color) {
for ($i = 0; $i -lt $Text.Length; $i++) {
Write-Host $Text[$i] -Foreground $Color[$i] -NoNewLine
}
Write-Host
}
# load the assembly
[void] [Reflection.Assembly]::LoadFile("C:\Progs\EwsManagedApi\Microsoft.Exchange.WebServices.dll")
# set ref to exchange, first references 2007, 2nd is 2010 (default)
$s = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)
#$s = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService
# use first option if you want to impersonate, otherwise, grab your own credentials
#$s.Credentials = New-Object Net.NetworkCredential($username, $password, $domain)
#$s.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$s.UseDefaultCredentials = $true
# discover the url from your email address
$s.AutodiscoverUrl($email)
# get a handle to the inbox
$inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($s,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)
#create a property set (to let us access the body & other details not available from the FindItems call)
$psPropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$psPropertySet.RequestedBodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::Text;
$items = $inbox.FindItems(5)
#set colours for Write-Color output
$colorsread = "Yellow","White"
$colorsunread = "Red","White"
# output unread count
Write-Color -Text "Unread count: ",$inbox.UnreadCount -Color $colorsread
foreach ($item in $items.Items)
{
# load the property set to allow us to get to the body
$item.load($psPropertySet)
# colour our output
If ($item.IsRead) { $colors = $colorsread } Else { $colors = $colorsunread }
#format our body
#replace any whitespace with a single space then get the 1st 100 chars
$bod = $item.Body.Text -replace '\s+', ' '
$bodCutOff = (100,$bod.Length | Measure-Object -Minimum).Minimum
$bod = $bod.Substring(0,$bodCutOff)
$bod = "$bod..."
# output the results - first of all the From, Subject, References and Message ID
write-host "====================================================================" -foregroundcolor White
Write-Color "From: ",$($item.From.Name) $colors
Write-Color "Subject: ",$($item.Subject) $colors
Write-Color "Body: ",$($bod) $colors
write-host "====================================================================" -foregroundcolor White
""
}
# display the newest 5 items
#$inbox.FindItems(5)
# display the unread items from the newest 5
#$inbox.FindItems(5) | ?{$_.IsRead -eq $False} | Select Subject, Sender, DateTimeSent | Format-Table -auto
# returns the number of unread items
# $inbox.UnreadCount
#see these URLs for more info
# EWS
# folder members: https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.folder_members%28v=exchg.80%29.aspx
# exporting headers: http://www.stevieg.org/tag/how-to/
# read emails with EWS: https://social.technet.microsoft.com/Forums/en-US/3fbf8348-2945-43aa-a0bc-f3b1d34da27c/read-emails-with-ews?forum=exchangesvrdevelopment
# Powershell
# multi-color lines: http://stackoverflow.com/a/2688572
# download the Exchange Web Services Managed API 1.2.1 from
# http://www.microsoft.com/en-us/download/details.aspx?id=30141
# extract somewhere, e.g. ...
# msiexec /a C:\Users\YourUsername\Downloads\EwsManagedApi.msi /qb TARGETDIR=C:\Progs\EwsManagedApi
एह? बंद करने के लिए वोट क्यों? –
आपको इसे स्थानीय कंप्यूटर पर जांचने की आवश्यकता है जिसमें ओलुक क्लाइंट स्थापित है या एक्सचेंज सर्वर पर (संभवतः क्लाइंट नहीं है)? क्या यह एक मुफ्त समाधान होना चाहिए? –
मैं एक ईमेल से लिंक प्राप्त करने के लिए दृष्टिकोण खोलने का विकल्प चाहता हूं। तो आइए मान लें कि दृष्टिकोण स्थापित नहीं है और हां, मैं इसे मुक्त करना चाहता हूं क्योंकि मैं इसे पॉशकोड पर रखना चाहता हूं। मैं कुछ खुदाई कर रहा हूं और वास्तव में पॉप 3 शायद ठीक काम करेगा। –