4

I am trying to send an email from Linux server, I want to send an image, not as an attachment, that should be displayed in the message body.

I tried.

mailx -s "TEST mail" <MASKED>@mask.com < download.JPEG

The above command gave a random junk data in the body of the mail

mailx --append "Content-type: text/html" -s "TEST mail" <MASKED>@mask.com < download.JPEG

The above command didn't work

mutt -a "download.JPEG" <MASKED>@mask.com -s "TEST mail" < /dev/null

The above command sent the image as an attachment.

UUENCODE is not installed in our server, so we shouldn't use the same.

I don't want anyone of the above. I want my picture to be displayed on the body of my mail instead.

Any help on this is highly appreciated.

1
  • It is not recommended sending it in raw binary. I actually prefer mpack to uuencode. Install it. Jun 5, 2018 at 11:48

3 Answers 3

3

To get the picture to be displayed in-line, it must be encoded as a valid MIME object with a Content-Disposition: inline header in it.

The mpack command can do this.

Try sending an email like this:

mpack -s "TEST mail" -c image/jpeg download.JPEG <MASKED>@example.com

Or if you want to output the result into a file instead of sending it directly:

mpack -s "TEST mail" -c image/jpeg download.JPEG -o email-with-image.txt

Then you can send it later with e.g.:

mailx <MASKED>@example.com < email-with-image.txt

If you want to add text to your message before the image, write it into a file, and add a -d text-before.txt option to the mpack command. For adding text after the image, just appending it to the mpack-produced file should work.

2

You can use the below command.

Command

mutt -e "set content_type=text/html" -a lb.png -s "Test Mail" user@example.com < mail.html

mail.htm

<img src="cid:lb.png" />

Reference: Display attached image in email body

3
  • Can't stat user@example.com: No such file or directory user@example.com: unable to attach file. same with any other email address. Mutt 1.5.21 (2010-09-15)
    – WebOrCode
    Nov 18, 2020 at 18:01
  • I have: Can't stat my@email.com: No such file or directory too
    – andreykyz
    Feb 22, 2021 at 18:40
  • The recipient should come before options like this: mutt user@example.com -e "set content_type=text/html" -a lb.png -s "Test Mail" < mail.html
    – SSK
    Mar 2, 2021 at 6:14
0

sendimagemail is a 100 line bash wrapper for sendmail(msmtp implement), which supports sending multiple jpg/png/gif inline images and text to gmail/outlook/qq/163 services. Here is the manual.

sendimagemail dst [image...] [--cc=''] [--bcc=''] [--subject='20210315 00:33:52'] [--body=''] [--dry] -- [sendmail-option]

# send text/html to one or more residents, with Cc and Bcc
sendimagemail bilabila@qq.com --body='Hi bilabila' --subject='Hi bilabila'
sendimagemail bilabila@qq.com --body='<div style=color:lightslategray>Hi bilabila<div/>'
sendimagemail 'qq bilabila@qq.com, google bilabila@gmail.com' --cc='163 bilabila@163.com' --bcc='ms bilabila@live.com'

# send one or more images
sendimagemail bilabila@qq.com a.jpg
sendimagemail bilabila@qq.com --body='<div>images</div>' a.jpg b.png c.gif

# send with non-default account
sendimagemail bilabila@qq.com a.jpg -- -a google
sendimagemail bilabila@qq.com a.jpg -- --from=bilabila@qq.com --host=smtp.qq.com --user=bilabila --passwordeval='echo TOKEN' --port 587 --auth --tls
sendimagemail bilabila@qq.com a.jpg -- --from=bilabila@163.com --host=smtp.163.com --user=bilabila@163.com --passwordeval='echo TOKEN' --port 25 --auth --tls
sendimagemail bilabila@qq.com a.jpg -- --from=bilabila@gmail.com --host=smtp.gmail.com --user=bilabila@gmail.com --passwordeval='echo TOKEN' --port 587 --auth --tls

# show what would be sent
sendimagemail bilabila@qq.com a.jpg --dry

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.