如何通过邮件从shell脚本发送特殊字符? [英] How to send special characters via mail from a shell script?

查看:150
本文介绍了如何通过邮件从shell脚本发送特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,运行在cron上,输出一些我们发送到'mail'程序的文本。一般行如下:

  ./ command.sh | mail -s我的主题destination@address.com  -  -F发件人姓名-f sender@address.com 

问题是脚本生成的文本有一些特殊字符 - é,ã,ç - 因为它不是英文。收到电子邮件后,每个字符都被替换为。



现在我明白,这很可能是因为编码设置不正确。

解决方案

我的 / usr / bin / mail 符号链接到 / etc / alternatives / mail ,它也符号链接到 / usr / bin / bsd-mailx



我必须在邮件头中指定自己的编码。 ( -S 不支持。)



cat myutf8-file | mail -aContent-Type:text / plain; charset = UTF-8-s我的主题me@mail.com


I have a script that runs on cron that outputs some text which we send to the 'mail' program. The general line is like this:

./command.sh | mail -s "My Subject" destination@address.com -- -F "Sender Name" -f sender@address.com

The problem is that the text generated by the script has some special characters - é, ã, ç - since it is not in english. When the e-mail is received, each character is replaced by ??.

Now I understand that this is most likely due to the encoding that is not set correctly. What is the easiest way to fix this?

解决方案

My /usr/bin/mail is symlinked to /etc/alternatives/mail which is also symlinked to /usr/bin/bsd-mailx

I had to specify myself the encoding in the mail header. (The -S is not supported here.)

cat myutf8-file | mail -a "Content-Type: text/plain; charset=UTF-8" -s "My Subject" me@mail.com

这篇关于如何通过邮件从shell脚本发送特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆