dmi*_*try 3 powershell pop3 imap
我只需要在PoSh脚本中收到电子邮件并查看其主题 - 使用pop3或imap,无关紧要.
我试图找到解决方案,但我找到的只是第三方.net assebmlies或MS Exchange直接工作.两者都不合适.
如何使用SMTP并发送电子邮件 - 它绝对清晰,但如何接收?是不是有类似于System.Net.Mail的标准程序集?
小智 5
这是我在c#上使用的代码.我已将dll导入powershell并使用它来检索消息的不同部分.我使用的DLL是Imapx2,它是一个开源的.我知道您不想使用第三方.NET程序集,但这可能有助于其他人尝试访问此内容.
### 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"
}
}
Run Code Online (Sandbox Code Playgroud)
我希望这可以帮到你
| 归档时间: |
|
| 查看次数: |
16306 次 |
| 最近记录: |