mailx将电子邮件发送到多个帐户

时间:2019-11-13 16:59:42

标签: bash shell ksh mailx

我正在尝试使用mailx通过外壳脚本发送电子邮件。

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
    <DependsOnNETStandard>true</DependsOnNETStandard>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.ServiceBus" Version="4.1.1" />
    <PackageReference Include="Microsoft.ApplicationInsights" Version="2.11.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="3.2.0" />
    <PackageReference Include="Microsoft.IdentityModel" Version="7.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.29" />
    <PackageReference Include="NETStandard.Library" Version="2.0.3" />
    <PackageReference Include="System.Text.Json" Version="4.6.0" />
  </ItemGroup>
  <ItemGroup>
    <None Include="******.cs" />
    <None Include="******.cs" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\************" />
    <ProjectReference Include="..\************" />
  </ItemGroup>
  <ItemGroup>
    <None Update="*******/function.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="*******/function.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

我的问题是我试图将以分号分隔的列表更改为以空格分隔的列表,因为我被告知这是mailx所需要的。

但是,响应为:

Message=<HTML><BODY><p>FINISHED</p></BODY></HTML>

Recipients=email1@email.org;email2@email.org
Recipients=$(echo "${Recipients}" | sed "s/;/ /g")
echo "Recipients:  ${Recipients}"

mailx -s "Ingestion Report ${EXT1}. $( echo "\nContent-Type: text/html")" "${Recipients}" < $MESSAGE

我在做什么错?谢谢。

1 个答案:

答案 0 :(得分:2)

分号是命令分隔符,因此您必须从以下位置更改定义Recipients的方式:

Recipients=email1@email.org;email2@email.org

收件人:

Recipients="email1@email.org;email2@email.org"

引用该值可防止将;解释为命令分隔符。

或者,您可以首先正确定义Recipients

Recipients="email1@email.org email2@email.org"

或者,如果由于某种原因您无法控制它,则可以放弃sed呼叫,然后执行以下操作:

mailx ... ${Recipients/;/ }