mailx发送html,linux - Mailx send html message - Stack Overflow

There are many different versions of mail around. When you go beyond mail -s subject to1@address1 to2@address2With some mailx implementations, e.g. from mailutils on Ubuntu or

Debian's bsd-mailx, it's easy, because there's an option for that.

mailx -a 'Content-Type: text/html' -s "Subject" to@address

With the Heirloom mailx, there's no convenient way. One possibility

to insert arbitrary headers is to set editheaders=1 and use an

external editor (which can be a script).

## Prepare a temporary script that will serve as an editor.

## This script will be passed to ed.

temp_script=$(mktemp)

cat <>"$temp_script"

1a

Content-Type: text/html

.

$r test.html

w

q

EOF

## Call mailx, and tell it to invoke the editor script

EDITOR="ed -s $temp_script" heirloom-mailx -S editheaders=1 -s "Subject" to@address <

~e

.

EOF

rm -f "$temp_script"

With a general POSIX mailx, I don't know how to get at headers.

If you're going to use any mail or mailx, keep in mind that

This isn't portable even within a given Linux distribution. For example, both Ubuntu and Debian have several alternatives for mail and mailx.

When composing a message, mail and mailx treats lines beginning with ~ as commands. If you pipe text into mail, you need to arrange for this text not to contain lines beginning with ~.

If you're going to install software anyway, you might as well install something more predictable than mail/Mail/mailx. For example, mutt. With Mutt, you can supply most headers in the input with the -H option, but not Content-Type, which needs to be set via a mutt option.

mutt -e 'set content_type=text/html' -s 'hello' 'to@address'

Or you can invoke sendmail directly. There are several versions of sendmail out there, but they all support sendmail -t to send a mail in the simplest fashion, reading the list of recipients from the mail. (I think they don't all support Bcc:.) On most systems, sendmail isn't in the usual $PATH, it's in /usr/sbin or /usr/lib.

cat <

To: to@address

Subject: hello

Content-Type: text/html

EOF

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值