I can send email from my gmail account by ssmtp in Linux now. But how can I attach files to the email?
To send an attachment, you need to encode the message using MIME.
You could use Mutt
mutt -s SUBJECT -a ATTACHMENT_FILE_1 ATTACHMENT_FILE_2 -- EMAIL_ADDRESS < MESSAGE_FILE
mpack -s SUBJECT -D MESSAGE_FILE ATTACHMENT_FILE EMAIL_ADDRESS
echo -e "to: firstname.lastname@example.org\nsubject: subject\n"| (cat - && uuencode /path/to/attachment attachment.name) | ssmtp email@example.com
This solution does not depend on mutt.
$ echo -e "to: firstname.lastname@example.org\nsubject: test\n"| (cat - && uuencode /path/to/file file.name) | ssmtp email@example.com
Provided that SSMTP is configured, and you've verified that messages without attachments are reaching their destination and does not depend on mutt.
$ sudo apt-get install uudeview $ echo -e "From: firstname.lastname@example.org\nTo: email@example.com\nSubject: mySubject\n\nBody-Text"|uuenview -a -bo MyAttachment|sendmail -t