将newline字符附加到shell / linux for mail命令中的消息

发布于 2025-02-06 18:22:04 字数 286 浏览 2 评论 0原文

将新线路附加到消息然后通过邮件发送的最佳方法是什么?

message=""

for f in $backupdir/*; do
    message+="..."
done
echo "$message" | mailx -a 'Content-Type: text/html' -s "[Test]" email

我找到消息+=“消息” $'\ n',但是在Outlook中打开该邮件时,这有一些错误 我尝试了使用HTML标签的MailX,但这根本没有附加新行。

What is the best way to append a new line to a message and then send that per mail?

message=""

for f in $backupdir/*; do
    message+="..."
done
echo "$message" | mailx -a 'Content-Type: text/html' -s "[Test]" email

i found message+="message"$'\n' but this has some bugs when opening that mail in outlook
i tried mailx with html tag but this does not append a new line at all.

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

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

发布评论

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

评论(2

最初的梦 2025-02-13 18:22:04

我找到了消息+=“ message” $'\ n',但是在Outlook

中打开该邮件时,这有一些错误

原因是您要求Mailx将邮件编码到HTML中。

如果您需要HTML电子邮件,那么您需要

message="${message}<p>Some new paragraph.</p>"
# ...
printf %s "$message" | mailx -a 'Content-Type: text/html' -s '[Test]' [email protected]

立即撰写HTML段落,如果您想发送纯文本消息,则常规的新线是可以的:

message="${message}Some new paragraph.
"
# Or Bash's c-style string to add the newline and concatenate string
message+=
Another paragraph\n'
 printf %s "$message" | mailx -a 'Content-Type: text/plain' -s '[Test]' [email protected]

i found message+="message"$'\n' but this has some bugs when opening that mail in outlook

The reason for this is because you asks mailx to encode the mail into HTML.

if you need an HTML email, then you need to compose HTML paragraphs

message="${message}<p>Some new paragraph.</p>"
# ...
printf %s "$message" | mailx -a 'Content-Type: text/html' -s '[Test]' [email protected]

Now if you want to send plain text messages, regular newlines are just fine:

message="${message}Some new paragraph.
"
# Or Bash's c-style string to add the newline and concatenate string
message+=
Another paragraph\n'
 printf %s "$message" | mailx -a 'Content-Type: text/plain' -s '[Test]' [email protected]
污味仙女 2025-02-13 18:22:04

使用HTML,您可以将&lt; br /&gt; < /code>标记放在消息中。

Using HTML, you can put the <br /> tag in the message.

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