如何使用linux mail命令在电子邮件中插入新行?

时间:2021-07-19 22:59:04

how to insert new line in the email using linux mail command?

如何使用linux mail命令在电子邮件中插入新行?

echo "Hi xxx, would you tell me something?\\n thanks!\\n -xxx" | mail -s "subject" xxx@gmail.com

The email shows the literal '\n', not a newline, how do fix it?

电子邮件显示字面'\ n',而不是换行符,如何解决?

4 个解决方案

#1


26  

Try using echo -e

尝试使用echo -e

echo -e "Hello \n World"

echo -e“Hello \ n World”

You can type man echo from the command line to read more.

您可以从命令行键入man echo以阅读更多内容。

#2


11  

With mailx, if you send the email to oultook user, you can add 2 spaces at the begenig of each line.

使用mailx,如果您将电子邮件发送给oultook用户,则可以在每行的begenig中添加2个空格。

{ echo "Hi xxx, would you tell me something" ; echo "thanks!" ; echo "-xxx" } | sed 's/^/  /g' | mailx -s "subject" xxx@domain.com

#3


1  

I encountered this issue and resolved it by surrounding with quotes the variable I was piping into mailx.

我遇到了这个问题并通过用引号括起来解决了这个问题。

I started with a list of processes from ps i.e. list="$(ps |grep some_process)".

我从ps开始了一个进程列表,即list =“$(ps | grep some_process)”。

Then when I tried to mail that out as follows, the newlines were obliterated:

然后,当我尝试按如下方式邮寄时,新线被删除:

echo $body | mailx -s "${subject}" recipient@someplace.com

But, simply wrapping $body with quotes preserved the newlines:

但是,简单地用引号括起$ body保留了换行符:

echo "$body" | mailx -s "${subject}" recipient@someplace.com

#4


0  

The accepted answer did not work for me when using the mail command, I had to use

使用mail命令时,接受的答案对我不起作用,我不得不使用

\r

My whole command is

我的全部命令是

mail -s "SUBJECT" -aFrom:"from@sdf.com "to@sdfd.com" <<< $( echo -e "Line1\rLine2")

#1


26  

Try using echo -e

尝试使用echo -e

echo -e "Hello \n World"

echo -e“Hello \ n World”

You can type man echo from the command line to read more.

您可以从命令行键入man echo以阅读更多内容。

#2


11  

With mailx, if you send the email to oultook user, you can add 2 spaces at the begenig of each line.

使用mailx,如果您将电子邮件发送给oultook用户,则可以在每行的begenig中添加2个空格。

{ echo "Hi xxx, would you tell me something" ; echo "thanks!" ; echo "-xxx" } | sed 's/^/  /g' | mailx -s "subject" xxx@domain.com

#3


1  

I encountered this issue and resolved it by surrounding with quotes the variable I was piping into mailx.

我遇到了这个问题并通过用引号括起来解决了这个问题。

I started with a list of processes from ps i.e. list="$(ps |grep some_process)".

我从ps开始了一个进程列表,即list =“$(ps | grep some_process)”。

Then when I tried to mail that out as follows, the newlines were obliterated:

然后,当我尝试按如下方式邮寄时,新线被删除:

echo $body | mailx -s "${subject}" recipient@someplace.com

But, simply wrapping $body with quotes preserved the newlines:

但是,简单地用引号括起$ body保留了换行符:

echo "$body" | mailx -s "${subject}" recipient@someplace.com

#4


0  

The accepted answer did not work for me when using the mail command, I had to use

使用mail命令时,接受的答案对我不起作用,我不得不使用

\r

My whole command is

我的全部命令是

mail -s "SUBJECT" -aFrom:"from@sdf.com "to@sdfd.com" <<< $( echo -e "Line1\rLine2")