[英]Script to send new files via email from monitored folder
I'm wondering if anyone can point me in the direction of how to automate the sending of newly added files located in a monitored folder via email (Exchange), ideally without Outlook installed on the server. 我想知道是否有人可以指出如何通过电子邮件(Exchange)自动发送位于受监视文件夹中的新添加文件的方向,理想情况下是在服务器上未安装Outlook的情况下。
I use scripts daily to notify me of changes in a watched folder via email, but none of these actually attach the files on the email, and at best only list the new files names etc. 我每天使用脚本通过电子邮件通知我监视文件夹中的更改,但是这些脚本实际上都没有将文件附加到电子邮件中,并且充其量仅列出新文件的名称等。
We have software that outputs 3 small text files at roughly the same time day, but someone then has to email those manually to the same external address each day. 我们提供的软件可以在大约同一时间输出3个小文本文件,但是有人每天都必须手动将其发送到相同的外部地址。 I'd like to automate that process.
我想自动化该过程。
I'm running Server 2008 R2, and don't mind PowerShell and VB etc. Any help is appreciated. 我正在运行Server 2008 R2,并且不介意PowerShell和VB等。感谢您的任何帮助。
Thank you. 谢谢。
This should get you going. 这应该可以帮助您。
$watchPath = "c:\folder\" $sendToList = @("toUser@domain.com") $sendFrom = "fromUser@domain.com" $emailSubject = "File '{0}' changed" $smtpHost = "smtp.server" $watcher = New-Object System.IO.FileSystemWatcher $watcher.Path = $watchPath $watcher.IncludeSubdirectories = $false $watcher.EnableRaisingEvents = $true $changed = Register-ObjectEvent $watcher "Changed" -Action { Send-MailMessage -SmtpServer $smtpHost -To $sendToList -from $sendFrom -Subject ($emailSubject -f $eventArgs.Name) -Attachments $eventArgs.FullPath }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.