Solved

PowerShell Receive eMail

Posted on 2013-02-05
5
1,989 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 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

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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