使用PowerShell获取电子邮件 [英] Get email using PowerShell

查看:321
本文介绍了使用PowerShell获取电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所需要的只是在PowerShell脚本中获取电子邮件,然后查看其主题-与pop3或imap无关.
我试图找到解决方案,但发现的只是第3方.net组件或MS Exchange直接工作.两者都不适合.
如何使用SMTP和发送电子邮件-绝对清楚,但如何接收?没有类似于System.Net.Mail的标准程序集吗?

All I need is get email in PowerShell Script and see at its topic - with pop3 or imap, doesnt matter.
I tried to find solution, but all I found is either 3rd party .net assebmlies, or MS Exchange direct work. Both are not appropriate.
How to use SMTP and send email - its absolutely clear, but how to receive? Isn't there any standard assemblies similar to System.Net.Mail?

推荐答案

这是我在c#上一直使用的代码.我已经将dll导入了powershell,并用它来检索消息的不同部分.我使用的dll是Imapx2,这是一个开放源代码.我了解您不希望使用第三方.NET程序集,但这可能会帮助其他尝试访问此内容的人.

Here is a code I have been using on c#. I have Imported the dll to powershell and used it to retrieve different parts of a message. The dll I used is Imapx2 which is an open source. I understand that you don't want to use a third party .NET assemblies but this might help other people trying to reach to this content.

### Import the dll
[Reflection.Assembly]::LoadFile("YourDirectory\imapx.dll")
### Create a client object
$client = New-Object ImapX.ImapClient
###set the fetching mode to retrieve the part of message you want to retrieve, 
###the less the better
$client.Behavior.MessageFetchMode = "Full"
$client.Host = "imap.gmail.com"
$client.Port = 993
$client.UseSsl = $true
$client.Connect()
$user = "User"
$password = "Password"
$client.Login($user,$password)
$messages = $client.Folders.Inbox.Search("ALL", $client.Behavior.MessageFetchMode, 1000)
foreach($m in $messages){
$m.Subject
foreach($r in $m.Attachments){
$r | Out-File "Directory"
    }
 }

我希望这会有所帮助

这篇关于使用PowerShell获取电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆