简体   繁体   English

使用Bash中的mail或mailx将图像附加到电子邮件正文中

[英]Attach image in the email body using mail or mailx in Bash

I want to attach an image in email body using the mail or mailx from shell script. 我想使用shell脚本中的mailmailx在电子邮件正文中附加图像。 mutt and sendmail utilities is not available and I dont have privileges to install those. muttsendmail实用程序不可用,我没有权限安装它们。

uuencode is also not available uuencode也不可用

First I tried sending the HTML content using mailx using the below command and it didnt work. 首先,我尝试使用mailx使用以下命令发送HTML内容,但它没有用。 It just send the raw data with html tags to the mail 它只是将带有html标签的原始数据发送到邮件

export body="<html><header><title>This is title</title></header><body>Hello world</body></html>"
echo $body | mailx -S "MIME-Version: 1.0" -S "Content-Type: text/html" -vvv -s "test mail" -r sender@xx.com reciever@yy.com

I tried append-headers with the option -a and it didnt work since -a is meant for attachment 我尝试使用选项-a附加标题,但它没有用,因为-a用于附件

And also tried with below command and it just attaches the image and not visible in the body. 并且还尝试使用以下命令,它只是附加图像而在身体中不可见。

mailx -s "test mail" -r sender@xx.com reciever@yy.com < Capture.PNG

Can anyone help me with the correct way to send a email with picture in the body 任何人都可以帮助我以正确的方式发送带有图片的电子邮件

发送附件的一种可能方法是使用如下命令:

uuencode Capture.PNG Capture.PNG|mailx -s "test mail" -r sender@xx.com reciever@yy.com

Simplest answer: 最简单的答案:

 mail -s "the subject" -a attachment.xyz you@email.com < body.txt

If that doesn't work for you, use multipart MIME. 如果这不适合您,请使用multipart MIME。 cf this post on Stack Exchange for an example. 以Stack Exchange上的这篇文章为例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM