简体   繁体   English

通过电子邮件从受监视的文件夹发送新文件的脚本

[英]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.

相关问题 如何通过 outlook email 从文件夹中发送所有 excel 文件 - How can i send all excel files from a folder via outlook email 用于发送包含文件夹中文件列表的电子邮件的 Powershell 脚本 - 格式问题 - Powershell script to send email with list of files in a folder - formatting issue Qmail。 从Maildir \\ new文件夹发送电子邮件 - Qmail. Send email from Maildir\new folder 在 python 脚本中通过邮件命令发送电子邮件 - Send email via mail command in python script 通过 email 将 excel 范围作为新工作表发送 - send excel range as new worksheet via email 从PHP脚本发送电子邮件 - Send Email from PHP Script 从收件箱中删除电子邮件,并通过规则-> 脚本从已删除项目文件夹中删除它 - Delete email from inbox and also delete it from deleted-items folder via rule->script 如何使用 Python 从文件夹中发送 email 中的随机 pdf 文件? - How can I send random pdf files in email from a folder using Python? iphone:通过外部服务器(使用PHP脚本)从我的应用发送电子邮件是否合法 - iphone : Is it legal to send an email from my app via an external server (with a PHP script) 电子邮件通过perl脚本而不是shell脚本发送作品 - email send works via perl script but not shell script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM