Solved

PowerShell Receive eMail

Posted on 2013-02-05
5
1,918 Views
Last Modified: 2013-02-05
Hi :o)
It is possible to send an email using Send-MailMessage.
But how to receive without using 3. Party software?
I am looking for a solution like Send-MailMessage ex. Receive-MailMessage.

Br....
0
Comment
Question by:tekniker53
  • 3
  • 2
5 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 38854644
basically you want to read your inbox via powershell.
to do that you need the following:
1. download and install Exchange Web Services Managed API 1.2.1
2. locate Microsoft.Exchange.WebServices.dll on your file system.
should be located under C:\Program Files\Microsoft\Exchange\Web Services\1.0
3. use the following code to get the last email received:

[Reflection.Assembly]::LoadFile("C:\Program Files\Microsoft\Exchange\Web Services\1.0\Microsoft.Exchange.WebServices.dll")
$s = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)
$s.Credentials = New-Object Net.NetworkCredential('user', 'pass', 'domain')
$s.AutodiscoverUrl("email@address.com")

$inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($s,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)
$inbox.FindItems(1)

Open in new window


from:
http://stackoverflow.com/questions/4454165/how-to-check-an-exchange-mailbox-via-powershell
0
 

Author Comment

by:tekniker53
ID: 38854715
thanks, I get some errors regarding auodiscover service...

(we are using Office365.)

GAC    Version        Location                                                                              
---    -------        --------                                                                              
False  v2.0.50727     C:\Program Files\Microsoft\Exchange\Web Services\1.2\Microsoft.Exchange.WebServices.dll
Exception calling "AutodiscoverUrl" with "1" argument(s): "Autodiscover blocked a potentially insecure redire
ction to https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml. To allow Autodiscover to follow th
e redirection, use the AutodiscoverUrl(string, AutodiscoverRedirectionUrlValidationCallback) overload."
At line:4 char:1
+ $s.AutodiscoverUrl("my-testaccount@domain.dk")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : AutodiscoverLocalException
 
Exception calling "Bind" with "2" argument(s): "The Url property on the ExchangeService object must be set."
At line:6 char:1
+ $inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($s,[Microsoft.Exchan ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ServiceLocalException
 
You cannot call a method on a null-valued expression.
At line:7 char:1
+ $inbox.FindItems(1)
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 38854765
change line 4 to:

$service.AutodiscoverUrl("email@address.com", {$true})

Open in new window

0
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 500 total points
ID: 38854782
also you wanna look at this post:
Exchange Managed API autodiscover with Powershell
0
 

Author Closing Comment

by:tekniker53
ID: 38856700
Thanks for quick response :o)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
This video discusses moving either the default database or any database to a new volume.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question