如何让 ssmtp 将本地用户映射到收件人:字段的电子邮件地址

如何让 ssmtp 将本地用户映射到收件人:字段的电子邮件地址

我有一个简单的ssmtp设置。

该命令echo test | mail -s "testing" username总是导致我尝试发送一封电子邮件,但username@hostname总是失败。

因此,我尝试将本地用户名映射到特定的电子邮件地址。

我该怎么做呢?

我试过了/etc/aliases,但是

$ sudo newaliases 
newaliases: Aliases are not used in sSMTP

然后我尝试

$ cat /etc/mail.rc 
alias root root<[email protected]>
alias username username<[email protected]>

但它仍然不起作用。有什么想法吗?

答案1

我也遇到了一些困难ssmtp。我学到的第一件事是别名机制才不是使用普通mail程序;我必须mailx从包中使用bsd-mailx——不知道为什么。因此,在开始更改配置之前,请先检查一下。

无论如何,作为参考,我有一个ssmtp如下的工作设置:

  1. 文件 /etc/ssmtp/ssmtp.conf

    #
    # Config file for sSMTP sendmail
    #
    # The person who gets all mail for userids < 1000
    # Make this empty to disable rewriting.
    [email protected]
    
    # The place where the mail goes. The actual machine name is required no 
    # MX records are consulted. Commonly mailhosts are named mail.domain.com
    mailhub=mymailserver.mymail.domain.com:25
    
    # Where will the mail seem to come from?
    rewriteDomain=mymail.domain.com
    
    # The full hostname
    hostname=myhostname.mymail.domain.com
    # Use SSL/TLS before starting negotiation 
    UseTLS=No
    #UseSTARTTLS=Yes
    #
    # 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=NO
    
  2. 文件/etc/ssmtp/revaliases/

    # sSMTP aliases
    # 
    # Format:   local_account:outgoing_address:mailhub
    #
    # Example: root:[email protected]:mailhub.your.domain[:port]
    # where [:port] is an optional port number that defaults to 25.
    #
    root:[email protected]
    romano:[email protected]
    postmaster:[email protected]
    

现在可以正常工作了:

[romano:~] % mailx -v root
Subject: test
test
.
Cc: 
[<-] 220 mymailserver.mymail.domain.com ESMTP my mail server
[->] HELO myhostname.mymail.domain.com
[<-] 250 mymailserver.mymail.domain.com
[->] MAIL FROM:<[email protected]>
[<-] 250 2.1.0 Ok
[->] RCPT TO:<[email protected]>
[<-] 250 2.1.5 Ok
[->] DATA
[<-] 354 End data with <CR><LF>.<CR><LF>
[->] Received: by myhostname.mymail.domain.com (sSMTP sendmail emulation); Fri, 03 Jul 2015 13:25:52 +0200
[->] From: "Romano Giannetti" <[email protected]>
[->] Date: Fri, 03 Jul 2015 13:25:52 +0200
[->] To: root
[->] Subject: test
[->] 
[->] test
[->] .
[<-] 250 2.0.0 Ok: queued as BF1CB3BC050
[->] QUIT
[<-] 221 2.0.0 Bye

请注意,此处的域名、主机名等均已加密,以保护隐私(因此可能会出现拼写错误)

相关内容