邮箱将发件人名称显示为“Apache”,因为我正在自动发送的邮件是从 Perl CGI 程序发送的。我如何将其更改为其他内容?
6 回答
您只需要添加一个From:
标题。默认情况下没有。
echo "Test" | mail -a "From: Someone <someone@example.com>" other@example.com
您可以使用以下命令添加任何自定义标头-a
:
echo "Test" | mail -a "From: Someone <someone@example.com>" \
-a "Subject: This is a test" \
-a "X-Custom-Header: yes" other@example.com
mail -s "$(echo -e "This is the subject\nFrom: Paula <johny@paula.com>\n
Reply-to: 1232564@yourserver.com\nContent-Type: text/html\n")"
milas.josh@gmail.com < htmlFileMessage.txt
以上是我的解决方案..只需将“Paula”替换为您想要的任何名称,例如 Johny Bravo..可以在 from 之后和回复之前添加任何额外的标题...只要确保您知道之前的标题语法添加它们....这对我来说非常有用。
您可以使用“-r”选项设置发件人地址:
mail -r me@example.com -s ...
如果您还想在发件人字段中包含您的真实姓名,您可以使用以下格式
mail -r "me@example.com (My Name)" -s "My Subject" ...
如果未在电子邮件标头中指定 From: 标头,则 MTA 使用当前用户的全名,在本例中为“Apache”。您可以在 /etc/passwd 中编辑完整的用户名
这取决于您正在谈论的发件人地址。收件人邮件程序中可见的发件人地址是从“发件人:”标头中提取的。这可能很容易从您的程序中设置。
如果您谈论的是 SMTP 信封发件人地址,您可以将 -f 参数传递给 sendmail 二进制文件。根据服务器配置,您可能不允许对 apache 用户执行此操作。
从 sendmail手册页:
-f <address>
This option sets the address of the envelope sender of a
locally-generated message (also known as the return path).
The option can normally be used only by a trusted user, but
untrusted_set_sender can be set to allow untrusted users to
use it. [...]
在 Ubuntu 14.04 上,这些建议都不起作用。Postfix 将覆盖登录系统用户作为发件人。起作用的是此链接中列出的以下解决方案->从root@servername更改外发邮件地址-rackspace sendgrid postfix
脚步:
1) 确保在 /etc/postfix/main.cf 中设置:
smtp_generic_maps = hash:/etc/postfix/generic
2) echo 'www-data yourusername@yourdomain.com' >> /etc/postfix/generic
3) sudo postmap /etc/postfix/generic
4) sudo 服务后缀重启