I can send email from my gmail account by ssmtp in Linux now. But how can I attach files to the email?
Asked
Active
Viewed 3.7k times
18
-
swaks : https://jetmore.org/john/code/swaks/faq.html#send_html_email should do the trick, and is built for automation as that seems to be your goal. – Nicholas Saunders Dec 19 '23 at 13:50
5 Answers
26
echo -e "to: receiver@domain.tld\nsubject: subject\n"| (cat - && uuencode /path/to/attachment attachment.name) | ssmtp receiver@gmail.com
This solution does not depend on mutt.
-
4
-
3By the way, SSMTP is used by many people to send automated E-mails through Gmail: http://www.nixtutor.com/linux/send-mail-with-gmail-and-ssmtp/ – metrix Sep 16 '13 at 15:23
-
2I 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 01 '14 at 19:18
-
24 years later, July 2017 - This is the answer I was looking for. Thank you, @metrix! – SDsolar Jul 21 '17 at 05:09
-
-
9
-
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
-
3It's possible, but you'd have to generate all the MIME headers somehow. Why do you need to only use
ssmtp
? Ifssmtp
provides/usr/lib/sendmail
or/usr/sbin/sendmail
, any local mail program should be able to send viassmtp
. – Mikel Jul 26 '12 at 15:34 -
3@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 04:47
1
$ 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.
0
$ 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

Michi
- 9
0
another alternative to uuencode is to use base64 commend instead ->
cat msg_source.txt | (cat - base64 && attachment.bin) | ssmtp -vvvv email@domain.com
where msg_source.txt contains header tags, like To:, From:, Subject:, Content-Type:, etc

Zonder
- 1