Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can send email from my gmail account by ssmtp in Linux now. But how can I attach files to the email?

share|improve this question
up vote 7 down vote accepted

To send an attachment, you need to encode the message using MIME.

You could use Mutt


or mpack


See also:

share|improve this answer
Thanks. So is that to say that it is NOT possible to send an attachment by ssmtp alone? – deepsky Jul 26 '12 at 15:26
It's possible, but you'd have to generate all the MIME headers somehow. Why do you need to only use ssmtp? If ssmtp provides /usr/lib/sendmail or /usr/sbin/sendmail, any local mail program should be able to send via ssmtp. – Mikel Jul 26 '12 at 15:34
@deepsky ssmtp is not a user interface. It's an MTA (mail transport agent), which is infrastructure meant to be accessed via an MUA (mail user agent, also known as a "mailreader"). It's sort of impressive that you were able to wrangle ssmtp by yourself without an MUA, but it's not a reasonable method of doing things. It's a good network-debugging skill you've learned though! – Alan Curry Jul 27 '12 at 4:47
echo -e "to: receiver@domain.tld\nsubject: subject\n"| (cat - && uuencode /path/to/attachment attachment.name) | ssmtp sender@gmail.com

This solution does not depend on mutt.

share|improve this answer
How is this getting a negative vote? it solves the problem. – metrix Sep 16 '13 at 14:43
By the way, SSMTP is used by many people to send automated E-mails through Gmail: nixtutor.com/linux/send-mail-with-gmail-and-ssmtp – metrix Sep 16 '13 at 15:23
I know this answer came in over a year after the question was asked, but this is the answer to the question. Works great, thanks. – RTF Aug 1 '14 at 19:18
$ echo -e "to: receiver@domain.tld\nsubject: test\n"| (cat - && uuencode /path/to/file file.name) | ssmtp sender@gmail.com

Provided that SSMTP is configured, and you've verified that messages without attachments are reaching their destination and does not depend on mutt.

share|improve this answer
I don't think this answers the original question. – slm Sep 2 '13 at 3:10
 $ sudo apt-get install uudeview
 $ echo -e "From: myaddress@mydomain.com\nTo: youraddress@yourdomain.com\nSubject: mySubject\n\nBody-Text"|uuenview -a -bo MyAttachment|sendmail -t
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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