Solved

PowerShell Receive eMail

Posted on 2013-02-05
5
2,047 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

691 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