Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将“更改为”;发件人:“;“Unix中的地址”;邮购;_Unix_Email - Fatal编程技术网

将“更改为”;发件人:“;“Unix中的地址”;邮购;

将“更改为”;发件人:“;“Unix中的地址”;邮购;,unix,email,Unix,Email,使用mail TO_ADDR从Unix命令行发送消息会导致从$USER@$HOSTNAME发送电子邮件。是否有办法更改通过邮件插入的“发件人:”地址 作为记录,我在Ubuntu上使用GNU Mailutils 1.1/1.2(但我在Fedora和RHEL上也看到了同样的行为) [编辑] $ mail -s Testing chris@example.org Cc:

使用
mail TO_ADDR
从Unix命令行发送消息会导致从
$USER@$HOSTNAME
发送电子邮件。是否有办法更改通过
邮件插入的“发件人:”地址

作为记录,我在Ubuntu上使用GNU Mailutils 1.1/1.2(但我在Fedora和RHEL上也看到了同样的行为)

[编辑]

$ mail -s Testing chris@example.org Cc: From: foo@bar.org Testing . $mail-s测试chris@example.org 复写的副本: 发件人:foo@bar.org 测试 . 屈服

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 主题:测试 致: X-Mailer:mail(GNU Mailutils 1.1) 消息Id: 发件人: 日期:2008年9月10日星期三13:17:23-0400 发件人:foo@bar.org 测试 “来源:foo@bar.org行是消息正文的一部分,而不是标题的一部分。

以下是一些选项:

  • 如果您有足够的特权,请将sendmail配置为使用泛型表进行重写

  • 自己编写整个邮件头(或将其邮寄给自己,用所有邮件头保存整个邮件,然后重新编辑,并从命令行使用rmail发送)

  • 使用sendmail直接发送,使用“-f”命令行标志,不要在邮件中包含“发件人:”行

这些并不完全相同,但我会让你进一步研究

在我的便携机上,我将sendmail作为客户端身份验证发送到一个邮件服务器,并使用泛型将返回的邮件发送到另一个帐户。它就像一个符咒。 我使用fetchmail聚合传入邮件。

在我的邮件版本(Debian linux 4.0)中,以下选项用于控制源/回复地址

  • -a开关,用于应用其他邮件头,在命令行上提供一个From:邮件头,该邮件头将附加到发送邮件头
  • $REPLYTO环境变量指定Reply To:header
那么下面的顺序

export REPLYTO=cms-replies@example.com
mail -aFrom:cms-sends@example.com -s 'Testing'
结果,在我的邮件客户端中,是一封来自cms的邮件-sends@example.com,任何回复都将默认为cms-replies@example.com

注意:Mac OS用户:您没有-a,但您有$REPLYTO

注(2):CentOS用户,许多评论员都补充说,您需要使用
-r
而不是
-a

注(3):这个答案至少有十年历史了(1),当你从谷歌进来时,请记住这一点。

这对我很有用

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

在Centos 5.3上,我能够做到:

mail -s "Subject" user@address.com -- -f from@address.com < body
mail-s“主题”user@address.com----ffrom@address.com

双破折号阻止mail解析-f参数,并将其传递给sendmail本身。

GNU mailutils的“mail”命令不允许您这样做(至少很容易)。但如果安装“Herelomb mailx”,其mail命令(mailx)具有“-r”选项,可以从字段覆盖默认的“$USER@$HOSTNAME”

echo "Hello there" | mail -s "testing" -r sender@company.com recipient@company.com
适用于“mailx”,但不适用于“mail”

$ 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 $ls-l/usr/bin/mail lrwxrwx 1 root root 22 2010-12-23 08:33/usr/bin/mail->/etc/alternations/mail $ls-l/etc/备选方案/邮件 lrwxrwx 1 root root 23 2010-12-23 08:33/etc/alternations/mail->/usr/bin/herilomb mailx 谢谢你,博

mail -s "Subject" user@address.com -- -f from@address.com
我刚找到这个,它对我很有用。CentOS 5上mail 8.1的手册页没有提到这一点。对于
-f
选项,手册页上说:

-f从以文件操作数而不是系统邮箱命名的文件中读取邮件。(另请参阅文件夹)。如果未指定文件操作数,则从mbox而不是系统邮箱读取邮件


总之,这是一个很好的发现,谢谢。

我不知道它是否与其他操作系统相同,但在OpenBSD中,mail命令有以下语法:

mail to-addr ... -sendmail-options ...
sendmail有-f选项,您可以在其中指示发件人:字段的电子邮件地址

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

在CentOS 5.5上,我发现设置域默认值的最简单方法是修改主机文件。如果您的主机文件包含WAN/公共IP地址,只需修改为其列出的第一个主机名即可。例如,您的主机文件可能如下所示:


11.22.33.44本地主机默认域其他任何内容.com

要使其从whater-else.com发送,只需修改它,使whater-else.com首先列出,例如:


11.22.33.44which else.com本地主机默认域


我不能为任何其他发行版(甚至CentOS版本)说话,但在我的特殊情况下,上面的工作非常完美。

另外,最好使用
-F选项指定发件人的名称

大概是这样的:

mail -s "$SUBJECT" $MAILTO -- -F $MAILFROM -f ${MAILFROM}@somedomain.com
或者只需查看可用选项:

mail-s“$(echo-e)”这是主题\n来自:Paula\n
答复:1232564@yourserver.com\n内容类型:text/html\n““
米拉斯。josh@gmail.com

以上是我的解决方案……任何额外的标题都可以在“发件人”之后和“回复收件人”之前添加……只需确保在添加标题之前了解标题语法……这对我来说非常有效。

还可以使用以下方法设置“发件人”名称和“发件人”地址:

 echo test | mail -s "test" example@example.com -- -F'Some Name<example2@example.com>' -t
echo测试| mail-s“测试”example@example.com----F‘某个名字’-t

出于某种原因传递
-F'some Name'
-fexample2@example.com
不起作用,但将
-t
传递给sendmail很有效而且“简单”。

在CentOS上,这对我很有效:

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

以前提供的答案在CentOS5上对我不起作用。我安装了mutt。它有很多选项。使用mutt,您可以这样做:

export EMAIL=myfrom@example.com
export REPLYTO=myreplyto@example.com
mutt -s Testing chris@example.org

我从上面所有的答案中得出了这个结论。当我尝试每一个答案时,没有任何一个对我有效。我结合了上面所有的答案并得出了结论,做了很多尝试和错误。我不确定这是否对你有效,但它对我在联合国大学12.04和RHEL 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>'
echo“这是邮件的正文”|邮件-s“这是主题”,'-F'-F“
你可以发送m
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>'
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")
sudo apt-get install heirloom-mailx
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"