使用文本文件的内容发送电子邮件

时间:2018-02-25 10:38:29

标签: vba powershell

我希望创建一个脚本,在文本文件中查找日期,然后将电子邮件发送到相应的电子邮件地址。文本文件的结构如下:

25/02/2018, blah@email.com
26/02/2018, blue@email.com
etc

这将在Windows 2012的盒子上运行,所以理想情况下我想使用PowerShell。我不想依赖数据库,所以我认为可以搜索的简单文本文件可能是最简单的方法。基本上,这将用于发送特定事件的电子邮件警报,其中日期用于将电子邮件发送给正确的夜班工作人员。需要使用脚本作为我希望链接它的一些应用程序,几乎没有通知选项但是它们可以调用外部脚本。

感激地收到任何指导。

谢谢, 甲

1 个答案:

答案 0 :(得分:0)

你的问题很广泛;这是解决方案的大纲(作为脚本文件运行,PSv3 +):

# Declare a parameter for the target date.
param(
  [datetime] $TargetDate = [datetime]::Today
)

# Format the target date as a string to match the input file's date format.
$targetDateFormatted = (Get-Date -Date $TargetDate -Format 'dd/MM/yyyy')

# Specify the input file (CSV format, as implied by your sample data).
$inputFile = 'DateEmail.csv'

Import-Csv -Header Date, Email $inputFile | 
  Where-Object Date -eq $targetDateFormatted | 
    ForEach-Object {

      Write-Verbose -Verbose "Date is $($_.Date); email address is $($_.Email)"

      # Invoke the Send-MailMessage cmdlet here.

    }