如何使用 sSMTP 更改邮件命令的默认发件人地址?

Mar*_* B. 8 email mail smtp ssmtp

我已经安装:

  • sudo apt-get install ssmtp
  • sudo apt-get install mailutils

当我使用命令时:

echo "something" | mail -s "testing email" email@example.com
Run Code Online (Sandbox Code Playgroud)

生成的电子邮件将 From 字段设置为如下所示:

From: "Username" <username@local.domain.internal>
Run Code Online (Sandbox Code Playgroud)

是否有配置文件或其他内容,我可以在哪里更改此 FROM 默认地址?

请注意,更改 TO 字段很容易,如下所述:How to get ssmtp to map local user to email address for the To: field,但我需要更改默认的 FROM 字段。

编辑:我还需要更改发送邮件仿真的发件人地址。就我而言,Cron 设置了 FROM: root 和 TO: root,我想将其更改为普通电子邮件地址。

and*_*.46 8

ssmtp 中有几个设置可以操作以允许更改电子邮件的“发件人”字段:

  1. 里面有个设置/etc/ssmtp/ssmtp.conf。默认情况下,系统选择“发件人”地址,但可以通过取消选中 FromLineOverride 行来更改:

    # Are users allowed to set their own From: address?
    # YES - Allow the user to specify their own From: address
    # NO - Use the system generated From: address
    #FromLineOverride=YES
    
    Run Code Online (Sandbox Code Playgroud)

    “取消选中”是指删除该特定行开头的哈希标记。

  2. 可以有设置/etc/ssmtp/revaliases以允许来自每个用户的特定“发件人”行。中给出的示例revaliases相当无用:

    # Example: root:your_login@your.domain:mailhub.your.domain[:port]
    # where [:port] is an optional port number that defaults to 25.
    
    Run Code Online (Sandbox Code Playgroud)

    但是手册页给出了一个更明确的例子:

    A reverse  alias  gives  the From: address placed on a user's outgoing
    messages and (optionally) the  mailhub  these  messages  will  be  sent
    through. Example:
    
     root:jdoe@isp.com:mail.isp.com
    
    Messages  root  sends  will be identified as from jdoe@isp.com and sent
    through mail.isp.com.
    
    Run Code Online (Sandbox Code Playgroud)

我个人不使用 ssmtp 而是使用 msmtp,其中更改“发件人”字段的语法要简单得多,并且可以包含在文件中$HOME/.msmtprc

from my.email.address@myisp.com
Run Code Online (Sandbox Code Playgroud)

这要容易得多......

参考: