如何通过 UNIX mailx 命令发送电子邮件?

发布于 2024-08-21 21:35:52 字数 45 浏览 8 评论 0原文

如何通过 UNIX mailx 命令发送电子邮件?

How can I send an email through the UNIX mailx command?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

百变从容 2024-08-28 21:35:52

示例

$ echo "something" | mailx -s "subject" [email protected]

发送附件

$ uuencode file file | mailx -s "subject" [email protected]

和发送附件并写入消息正文的

$ (echo "something\n" ; uuencode file file) | mailx -s "subject" [email protected]

an example

$ echo "something" | mailx -s "subject" [email protected]

to send attachment

$ uuencode file file | mailx -s "subject" [email protected]

and to send attachment AND write the message body

$ (echo "something\n" ; uuencode file file) | mailx -s "subject" [email protected]
风追烟花雨 2024-08-28 21:35:52

在这里:

echo "Body" | mailx -r "FROM_EMAIL" -s "SUBJECT" "To_EMAIL"

PS。正文和主题应保留在双引号内。
替换电子邮件地址时,删除 FROM_EMAILTo_EMAIL 中的引号。

Here you are :

echo "Body" | mailx -r "FROM_EMAIL" -s "SUBJECT" "To_EMAIL"

PS. Body and subject should be kept within double quotes.
Remove quotes from FROM_EMAIL and To_EMAIL while substituting email addresses.

随梦而飞# 2024-08-28 21:35:52
mailx -s "subjec_of_mail" [email protected] < file_name

通过 mailx 实用程序,我们可以将文件从 unix 发送到 邮件服务器
在上面的代码中我们可以看到
第一个参数是-s“邮件主题”
第二个参数是邮件ID,最后一个参数是我们要附加的文件的名称

mailx -s "subjec_of_mail" [email protected] < file_name

through mailx utility we can send a file from unix to mail server.
here in above code we can see
first parameter is -s "subject of mail"
the second parameter is mail ID and the last parameter is name of file which we want to attach

奢欲 2024-08-28 21:35:52
mail [-s subject] [-c ccaddress] [-b bccaddress] toaddress

-c 和 -b 是可选的。

-s :指定主题;如果主题包含空格,则使用引号。

-c :将副本发送到以逗号分隔的用户列表。

-b :将密件抄送至以逗号分隔的用户列表。

希望我的回答能解答您的疑惑。

mail [-s subject] [-c ccaddress] [-b bccaddress] toaddress

-c and -b are optional.

-s : Specify subject;if subject contains spaces, use quotes.

-c : Send carbon copies to list of users seperated by comma.

-b : Send blind carbon copies to list of users seperated by comma.

Hope my answer clarifies your doubt.

一百个冬季 2024-08-28 21:35:52

会更快

echo "Body Of the Email"  | mutt -a "File_Attachment.csv" -s "Daily Report for $(date)"  -c [email protected] [email protected] -y
  1. 使用 MUTT 命令-c email cc list
  2. -s subject list
  3. -y 发送邮件

Its faster with MUTT command

echo "Body Of the Email"  | mutt -a "File_Attachment.csv" -s "Daily Report for $(date)"  -c [email protected] [email protected] -y
  1. -c email cc list
  2. -s subject list
  3. -y to send the mail
你好,陌生人 2024-08-28 21:35:52

从手册页:

发送邮件

要向一个或多个人发送消息,可以使用以下命令调用 mailx
参数的名称
邮件的收件人。
然后用户需要输入
他的消息,随后
在行首添加“control-D”。

换句话说,mailx 从标准输入读取要发送的内容,并且可以像平常一样重定向。例如:

ls -l $HOME | mailx -s "The content of my home directory" [email protected]

From the man page:

Sending mail

To send a message to one or more people, mailx can be invoked with
arguments which are the names of
people to whom the mail will be sent.
The user is then expected to type in
his message, followed
by an ‘control-D’ at the beginning of a line.

In other words, mailx reads the content to send from standard input and can be redirected to like normal. E.g.:

ls -l $HOME | mailx -s "The content of my home directory" [email protected]
穿透光 2024-08-28 21:35:52
echo "Sending emails ..."
NOW=$(date +"%F %H:%M")
echo $NOW  " Running service" >> open_files.log
header=`echo "Service Restarting: " $NOW`


mail -s "$header" [email protected],   \
              [email protected], \ < open_files.log
echo "Sending emails ..."
NOW=$(date +"%F %H:%M")
echo $NOW  " Running service" >> open_files.log
header=`echo "Service Restarting: " $NOW`


mail -s "$header" [email protected],   \
              [email protected], \ < open_files.log
許願樹丅啲祈禱 2024-08-28 21:35:52

这是一个多功能函数,用于处理带有多个附件的邮件发送:

enviaremail() {
values=$(echo "$@" | tr -d '\n')
listargs=()
listargs+=($values)
heirloom-mailx $( attachment=""
for (( a = 5; a < ${#listargs[@]}; a++ )); do
attachment=$(echo "-a ${listargs[a]} ")
echo "${attachment}"
done) -v -s "${titulo}" \
-S smtp-use-starttls \
-S ssl-verify=ignore \
-S smtp-auth=login \
-S smtp=smtp://$1 \
-S from="${2}" \
-S smtp-auth-user=$3 \
-S smtp-auth-password=$4 \
-S ssl-verify=ignore \
$5 < ${cuerpo}
}

函数调用:
enviaremail "smtp.mailserver:port" "from_address" "authuser" "'pass'" "destination" "list ofattachments split by space"

注意:删除调用中的双引号

另外请记住在使用该函数之前从外部定义电子邮件的 $titulo(主题)和 $cuerpo(正文)

Here is a multifunctional function to tackle mail sending with several attachments:

enviaremail() {
values=$(echo "$@" | tr -d '\n')
listargs=()
listargs+=($values)
heirloom-mailx $( attachment=""
for (( a = 5; a < ${#listargs[@]}; a++ )); do
attachment=$(echo "-a ${listargs[a]} ")
echo "${attachment}"
done) -v -s "${titulo}" \
-S smtp-use-starttls \
-S ssl-verify=ignore \
-S smtp-auth=login \
-S smtp=smtp://$1 \
-S from="${2}" \
-S smtp-auth-user=$3 \
-S smtp-auth-password=$4 \
-S ssl-verify=ignore \
$5 < ${cuerpo}
}

function call:
enviaremail "smtp.mailserver:port" "from_address" "authuser" "'pass'" "destination" "list of attachments separated by space"

Note: Remove the double quotes in the call

In addition please remember to define externally the $titulo (subject) and $cuerpo (body) of the email prior to using the function

℉服软 2024-08-28 21:35:52

自定义发件人地址

MESSAGE="SOME MESSAGE"
SUBJECT="SOME SUBJECT"
TOADDR="[email protected]"
FROM="DONOTREPLY"

echo $MESSAGE | mail  -s "$SUBJECT" $TOADDR  -- -f $FROM

Customizing FROM address

MESSAGE="SOME MESSAGE"
SUBJECT="SOME SUBJECT"
TOADDR="[email protected]"
FROM="DONOTREPLY"

echo $MESSAGE | mail  -s "$SUBJECT" $TOADDR  -- -f $FROM
动听の歌 2024-08-28 21:35:52

如果您想发送两个以上的人或 DL :

echo "Message Body" | mailx -s "Message Title" -r [email protected] [email protected],[email protected]

此处:

  • -s = 主题或邮件标题
  • -r = 发件人邮件或 DL

If you want to send more than two person or DL :

echo "Message Body" | mailx -s "Message Title" -r [email protected] [email protected],[email protected]

here:

  • -s = subject or mail title
  • -r = sender mail or DL
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文