?
Solved

PowerShell Receive eMail

Posted on 2013-02-05
5
Medium Priority
?
2,134 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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 2000 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Check out this step-by-step guide for using the newly updated Experts Exchange mobile app—released on May 30.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
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 shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Suggested Courses

752 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