Solved

PowerShell Receive eMail

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
In this video we show how to create an Accepted Domain in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Ac…
In this video we show how to create an email address policy in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Mail Flow…

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now