如何使用 MSbuild 向多个地址发送电子邮件

发布于 2024-07-13 15:42:20 字数 1096 浏览 8 评论 0原文

我的构建脚本中有一个目标,它将发送一封电子邮件,其中包含详细说明模块的 svn 更改的附件。

如果我对单个电子邮件地址进行硬编码,则此方法有效,但我现在想向多个开发人员发送电子邮件,并且脚本失败。 下面是代码

 <Target Name="MailInformationUpdate" DependsOnTargets="ZipArtifact" Condition="!Exists('BUILD_IS_PERSONAL')">

    <ReadLinesFromFile File="$(BuildDir)\$(recipientListFileName)">
      <Output PropertyName="Recipients"  TaskParameter="Lines"/>
    </ReadLinesFromFile>
    <Mail SmtpServer="$(smptServer)"
           To="@(Recipients)"
           From="$(senderEmail)"
           Body="Attached is a list of the changes made since the last release. "
       Subject="This module has been updated. You may wish to update." Attachments="$(BuildDir)\Builds\$(svnChangeFileName)"   
          />    
  </Target>

如果我将“收件人”行更改为 $(Recipients),列表中的第一个人将收到电子邮件,后续地址不会收到电子邮件。

然后,我将“收件人”行更改为您在@(收件人)下面看到的内容,因为我认为它可能会循环每个收件人。 没有这样的运气! 我收到错误消息

Emailing "{0}".
    <path> error : A recipient must be specified.

我读入的文件只是格式为 (emailAddress1)、(emailAddress2) 等的文本文件

I have a target in my build script that will send an email with an attachment detailing svn changes for a module.

This works if I hard code a single email address however I now want to email multiple developers and the script is failing. Below is the code

 <Target Name="MailInformationUpdate" DependsOnTargets="ZipArtifact" Condition="!Exists('BUILD_IS_PERSONAL')">

    <ReadLinesFromFile File="$(BuildDir)\$(recipientListFileName)">
      <Output PropertyName="Recipients"  TaskParameter="Lines"/>
    </ReadLinesFromFile>
    <Mail SmtpServer="$(smptServer)"
           To="@(Recipients)"
           From="$(senderEmail)"
           Body="Attached is a list of the changes made since the last release. "
       Subject="This module has been updated. You may wish to update." Attachments="$(BuildDir)\Builds\$(svnChangeFileName)"   
          />    
  </Target>

If I change the To line to read $(Recipients) the first person on the list will get the email, subsequent addresses do not recieve the email.

I then changed the To line to what you see below @(Recipients), as I thougt it might then loop round each recipient. No such luck!!! I get the error message

Emailing "{0}".
    <path> error : A recipient must be specified.

The file that I read in is simply a text file in the format (emailAddress1),(emailAddress2), etc

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无所的.畏惧 2024-07-20 15:42:20

任务ReadLinesFromFile从文本文件中读取项目列表。 但该文件的每一行必须有一个项目。

如果您的文本文件格式为 (emailAdress1),emailAddress2)...,您将只有一个包含 (emailAdress1),emailAddress2)... 的项目。
您的 email.txt 应该是这样的:

emailAdress1
emailAdress2
...

您从 ReadLinesFromFile 任务获取项目而不是属性,因此请像这样修改您的任务:(

<Target Name="MailInformationUpdate" DependsOnTargets="ZipArtifact" Condition="!Exists('BUILD_IS_PERSONAL')">

  <ReadLinesFromFile File="$(BuildDir)\$(recipientListFileName)">
    <Output ItemName="Recipients"  TaskParameter="Lines"/>
  </ReadLinesFromFile>
  <Mail SmtpServer="$(smptServer)"
       To="@(Recipients)"
       From="$(senderEmail)"
       Body="Attached is a list of the changes made since the last release. "
       Subject="This module has been updated. You may wish to update."
       Attachments="$(BuildDir)\Builds\$(svnChangeFileName)"   
      />    
</Target>

邮件目标的日志中存在错误,即使有多个收件人,也只会显示第一个收件人在日志中。)

The task ReadLinesFromFile reads a list of items from a text file. But the file must have one item on each line.

With your text file in the format (emailAdress1),emailAddress2)... you will only have one item containing (emailAdress1),emailAddress2)....
Your email.txt should be like this:

emailAdress1
emailAdress2
...

You get items from ReadLinesFromFile task and not properties, so modify your task like that:

<Target Name="MailInformationUpdate" DependsOnTargets="ZipArtifact" Condition="!Exists('BUILD_IS_PERSONAL')">

  <ReadLinesFromFile File="$(BuildDir)\$(recipientListFileName)">
    <Output ItemName="Recipients"  TaskParameter="Lines"/>
  </ReadLinesFromFile>
  <Mail SmtpServer="$(smptServer)"
       To="@(Recipients)"
       From="$(senderEmail)"
       Body="Attached is a list of the changes made since the last release. "
       Subject="This module has been updated. You may wish to update."
       Attachments="$(BuildDir)\Builds\$(svnChangeFileName)"   
      />    
</Target>

(There is a bug in the log of the mail target, even with multiple recipients only the first one will be shown in the log.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文