Ubuntu mailx 附加文件,不使用整个路径作为文件名

发布于 2025-01-16 22:44:30 字数 1549 浏览 0 评论 0原文

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

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

发布评论

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

评论(1

诠释孤独 2025-01-23 22:44:30

多种不同的 mailx 实现,因此具体的工作方式取决于您安装的版本。

但是,作为一种快速而肮脏的解决方法,您可以暂时 cd 进入该目录(前提是您具有对该目录的执行访问权限):

(  cd /home/dxduser/reports
   echo "This email is a test email" |
   mailx -s 'Test subject' [email protected] -A testreport.csv
)

括号在子 shell 中运行命令,以便 的效果cd 只会影响该子 shell,程序的其余部分可以像以前一样继续进行。

如果您的 mailx 实现放入 Content-Disposition: 并在文件名中包含文件的完整路径,我会将其视为错误。

另一种方法是使用不同的客户端。如果您无法安装例如 mutt,请创建一个简单的 shell 脚本包装器来围绕 base64quoted-printable 编码构建 MIME 结构你的 CSV 文件并不是特别难,但你必须知道你在做什么。简而言之,

( cat <<\:
Subject: test email
Content-type: text/csv
Content-disposition: attachment; filename="testreport.csv"
From: me <[email protected]>
To: you <[email protected]>
Content-transfer-encoding: base64

:
base64 </home/dxduser/reports/testreport.csv
) | /usr/lib/sendmail -oi -t

显然您必须安装 base64sendmail,并且可能会调整 sendmail 的路径(或者如果是的话则忽略它)在您的 PATH 中)。

There are multiple different mailx implementations around, so what exactly works will depend on the version you have installed.

However, as a quick and dirty workaround, you can temporarily cd into that directory (provided you have execute access to it):

(  cd /home/dxduser/reports
   echo "This email is a test email" |
   mailx -s 'Test subject' [email protected] -A testreport.csv
)

The parentheses run the command in a subshell so that the effect of the cd will only affect that subshell, and the rest of your program can proceed as before.

I would regard it as a bug if your mailx implementation puts in a Content-Disposition: with the full path of the file in the filename.

An alternative approach would be to use a different client. If you can't install e.g. mutt, creating a simple shell script wrapper to build the MIME structure around a base64 or quoted-printable encoding of your CSV file is not particularly hard, but you have to know what you are doing. In very brief,

( cat <<\:
Subject: test email
Content-type: text/csv
Content-disposition: attachment; filename="testreport.csv"
From: me <[email protected]>
To: you <[email protected]>
Content-transfer-encoding: base64

:
base64 </home/dxduser/reports/testreport.csv
) | /usr/lib/sendmail -oi -t

where obviously you have to have base64 and sendmail installed, and probably tweak the path to sendmail (or just omit it if it's in your PATH).

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