在邮件功能中设置发件人姓名

Ank*_*kur 15 linux mail-command

如何在 shell 脚本中使用 mail 命令设置发件人姓名和电子邮件地址。

Nol*_*nig 16

该选项-a填充标题。

快速命令:

mail -a FROM:sender@my-domain.com recipient@another-domain.fr
Run Code Online (Sandbox Code Playgroud)

长命令

mail --append="FROM:sender@my-domain.com" recipient@another-domain.fr
Run Code Online (Sandbox Code Playgroud)
 Usage: mail [OPTION...] [address...]

  -a, --append=HEADER: VALUE     append given header to 
                                 the message being sent

  -A, --attach=FILE              attach FILE
      --content-type=TYPE        set content type for 
                                 subsequent --attach options

  -e, --exist                    return true if mail exists
      --encoding=NAME            set encoding for subsequent 
                                 --attach options

  -E, --exec=COMMAND             execute COMMAND

  -F, --byname                   save messages according to sender

  -H, --headers                  write a header summary and exit

  -i, --ignore                   ignore interrupts

  -n, --norc                     do not read the system mailrc file

  -N, --nosum                    do not display initial header summary

  -p, --print, --read            print all mail to standard output

  -q, --quit                     cause interrupts to terminate program

  -r, --return-address=ADDRESS   use address as the return address 
                                 when sending mail

  -s, --subject=SUBJ             send a message with the given SUBJECT

  -t, --to                       precede message by a list of addresses

  -u, --user=USER                operate on USER's mailbox
Run Code Online (Sandbox Code Playgroud)

常用选项

  --config-file=FILE, --rcfile=FILE
                         load this configuration file

  --config-help          show configuration file summary

  --config-lint, --rcfile-lint
                         check configuration file syntax and exit

  --config-verbose, --rcfile-verbose
                         verbosely log parsing of the configuration files

  --no-site-config, --no-site-rcfile
                         do not load site configuration file

  --no-user-config, --no-user-rcfile
                         do not load user configuration file

  --set=PARAM=VALUE      set configuration parameter

  --show-config-options  show compilation options
Run Code Online (Sandbox Code Playgroud)

全局调试设置

--debug-level=LEVEL    set Mailutils debugging level

--debug-line-info      show source info with debugging messages

-?, --help             give this help list
    --usage            give a short usage message

-V, --version          print program version
Run Code Online (Sandbox Code Playgroud)

对于任何相应的短选项,长选项的强制性或可选参数也是强制性或可选的。


lcd*_*047 15

尝试这个:

mail -s 'Some Subject' -r 'First Last <you@example.com>' recipient@example.net
Run Code Online (Sandbox Code Playgroud)

这将设置From:和信封发件人。

  • `mail: 无效选项 -- 'r'` :( (2认同)
  • @DanielLoureiro 是的,[Heirloom mailx](http://heirloom.sourceforge.net/mailx.html) 有 `-r`,但 [POSIX] 不需要它(http://pubs.opengroup.org/ onlinepubs/9699919799/utilities/mailx.html)。对于 *BSD 和 Linux 来说还是足够好了。:) (2认同)

Lam*_*ert 6

这取决于您使用的是哪个邮件客户端。某些 Linux 发行版链接到mailx您可以使用该-r from-addr参数的位置。

如果你有 mutt 你应该可以使用mutt -e "set from='name <name@somewhere>'>.

具有该mail命令的其他发行版应该能够使用echo "test"|mail -s "subject" address@recipient.com -- -f from@address.