发送消息从Unix command line使用 mail TO_ADDR 结果在一封电子邮件 $USER@$HOSTNAME.有没有办法改变":"理由 mail?

为了记录在案,我使用的GNU Mailutils1.1/1.2在Ubuntu(但是我已经看到相同的行为与软呢帽和系统).

[编辑]

$ mail -s Testing chris@example.org                                                                  
Cc: 
From: foo@bar.org

Testing
.

产量

Subject: Testing
To: <chris@example.org>
X-Mailer: mail (GNU Mailutils 1.1)
Message-Id: <E1KdTJj-00025z-RK@localhost>
From: <chris@localhost>
Date: Wed, 10 Sep 2008 13:17:23 -0400

From: foo@bar.org

Testing

"From:foo@bar.org"行为消息的一部分身体,而不是部分的标题。

有帮助吗?

解决方案

在我的版本的邮件(Debian linux4.0)以下选项工作对于控制来源/回复地址

  • -一个 开关,附加头申请,提供一个:头上的命令行将所附的邮件发出头
  • $"回复" 环境可变指定一个答复:头

所以如下顺序

export REPLYTO=cms-replies@example.com
mail -aFrom:cms-sends@example.com -s 'Testing'

结果,在我的邮客户,为邮件cms-sends@example.com,任何答复将默认cms-replies@example.com

NB: Mac OS用户:你没有-有,但你没有 $"回复"

NB(2): CentOS用户,许多评论者已经增加,需要使用 -r-a

NB(3): 这答案是至少十岁(1),请铭记这一点,当你进来。

其他提示

在Centos5.3我能够做到:

mail -s "Subject" user@address.com -- -f from@address.com < body

双划停止邮件从分析-f参数,并将其传递给sendmail本身。

GNU mailutils的'邮件'的命令不让你这么做(很容易地在至少).但如果安装'的传家宝-mailx',其邮件的命令(mailx)具有'-r'项复盖默认的'$USER@$HOSTNAME'自的领域。

echo "Hello there" | mail -s "testing" -r sender@company.com recipient@company.com

作为'mailx"而不是"邮件'。

$ ls -l /usr/bin/mail
lrwxrwxrwx 1 root root 22 2010-12-23 08:33 /usr/bin/mail -> /etc/alternatives/mail
$ ls -l /etc/alternatives/mail
lrwxrwxrwx 1 root root 23 2010-12-23 08:33 /etc/alternatives/mail -> /usr/bin/heirloom-mailx
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

上述是我的解决方案。...任何额外头可以加入刚后从前答复...只是确保你知道你的头语法之前添加。这一工作完全适用于我。

加上这是很好的使用 -F option 指定名称的发送者。

事情是这样的:

mail -s "$SUBJECT" $MAILTO -- -F $MAILFROM -f ${MAILFROM}@somedomain.com

或者只是看看可用的选项:http://www.courier-mta.org/sendmail.html

这也有可能设置的两个自名称和地址的使用是这样的:

 echo test | mail -s "test" example@example.com -- -F'Some Name<example2@example.com>' -t

由于某些原因过 -F'Some Name'-fexample2@example.com 不工作,但通过在 -t sendmail工作和是"易"。

这里有一些选择:

  • 如果你有privelige足,配置sendmail做重写与泛型的表

  • 写入整个头自己(或邮寄给自己,拯救整个消息与所有的标题,并重新编辑和发送其与所有从命令行

  • 直接发送与sendmail,使用"f"命令行的标志,不包括你的"自:"线在你的消息

这些并不都是完全一样,但是我会让你看到它进一步。

在我的便携式,我已经发邮件进行认证,为一个客户到一个送邮件服务器和我使用仿制药,使返回的邮件来到另一个帐户。它就像一个特色。我总收邮件与fetchmail.

我不知道如果这是同其他操作系统,但是在OpenBSD,邮件命令具有这种语法:

mail to-addr ... -sendmail-options ...

sendmail有-f项,你指的电子邮件地址:领域。将以下命令对我的作品。

mail recepient@example.com -f from@example.com

谢谢博

mail -s "Subject" user@address.com -- -f from@address.com

我刚刚发现这和它对我的作品。人页的邮件8.1在CentOS5没有提到这一点。对于 -f 选项,人页说:

-f阅读邮件从文件命名的文件的操作数,而不是系统的邮箱。(亦参阅文件夹内。) 如果没有文件的操作数的规定,阅读邮件从mbox而不是系统的邮箱。

所以无论如何这是伟大的发现,谢谢。

我来这从以上所有答案。没有什么为我工作时,我想他们每一个人。我做了很多线索和错误的结合所有上述答复,并结束了这一点。我不知道如果这对你的作品但是它的工作对我来说在Ununtu12.04和系统5.4.

echo "This is the body of the mail" | mail -s 'This is the subject' '<receiver-id1@email.com>,<receiver-id2@email.com>' -- -F '<SenderName>' -f '<from-id@email.com>'

一个可以发送电子邮件的任何数量的人加入任何数量的接收身份证和邮件发送的 SenderNamefrom-id@email.com

希望这会有所帮助。

关于Debian7我仍然无法确定发件人的地址使用回答这个问题,(总会的名服务器),但解决这种方式。

安装 传家宝mailx

apt-get install heirloom-mailx

确保它是默认。

update-alternatives --config mailx

组成一个消息。

mail -s "Testing from & replyto" -r "sender <sender@example.com>" -S replyto="sender@example.com" recipient@example.net < <(echo "Test message")

echo "body" | mail -S from=address@foo.com "Hello"

-S您可以指定大量的串的选择,迄今为止最简单的方法的修改标题。

在CentOS这个工作对我说:

echo "email body" | mail -s "Subject here" -r from_email_address email_address_to

这个工作对我来说

echo "hi root"|mail -rsawrub@testingdomain.org -s'testinggg' root

在CentOS5.5,最简单的方法我已经找到了设置的默认自域是修改的主人的文件。如果你的主人的文件包含你的广域网/公共IP地址,只需修改一名列出。例如,你的主的文件可能看起来像:

...
11.22.33.44localhost default-domain whatever-else.com
...

让它发自whatever-else.com只需修改,这样whatever-else.com 是第一个列出,例如:

...
11.22.33.44 whatever-else.com localhost default-domain
...

我不能说的任何其他发行版(或甚至版本期的)但是,在我的特定情况下,上述工作。

回声"试验"|mailx-r fake@example.com -s'test'email@example.com

它的工作原理在OpenBSD.

是什么让我具有一定的回复地址在 Ubuntu 16.04UTF-8 编码和一个文件的附件:

安装邮件客户:

sudo apt-get install heirloom-mailx

编辑SMTP配置:

sudo vim /etc/ssmtp/ssmtp.conf
mailhub=smtp.gmail.com:587
FromLineOverride=YES
AuthUser=???@gmail.com
AuthPass=???
UseSTARTTLS=YES

发送邮件:

sender='send@domain.com'
recipient='recipient@domain.com'
zipfile="results/file.zip"
today=`date +\%d-\%m-\%Y`
mailSubject='My subject on the '$today
read -r -d '' mailBody << EOM
Find attached the zip file.

Regards,
EOM
mail -s "$mailSubject" -r "Name <$sender>" -S replyto="$sender" -a $zipfile $recipient < <(echo $mailBody)

没有上述解决方案是为我工作...

#!/bin/bash

# Message
echo "My message" > message.txt

# Mail
subject="Test"
mail_header="From: John Smith <john.smith@example.com>"
recipients="recipient@example.com"

#######################################################################
cat message.txt | mail -s "$subject" -a "$mail_header" -t "$recipients"

提供的答案之前,没有为我工作上的CentOS5.我安装了的笨蛋。它有很多的选择。与笨蛋你这样做,这种方式:

export EMAIL=myfrom@example.com
export REPLYTO=myreplyto@example.com
mutt -s Testing chris@example.org
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top