I am currently using the following command to send emails from my Ubuntu server, which I adapted from this question's answer: https://unix.stackexchange.com/a/90881/166614
printf "subject: the subject\n\nMessage body"| (cat - && uuencode "$attach" $(basename "$attach")) | ssmtp <email>
My only problem so far is that the command above creates two attachments consisting of the file indicated by the $attach variable and a text file containing what's supposed to be the message body with a seemingly random number for a name. If I remove the (cat - && uuencode "$attach" $(basename "$attach"))
command, the email has a body as it should but (obviously) no attachment. Conversely, if I remove the body, the text file attchment is not present.
Does anyone know how I can send an email through SSMTP with both a body and attachment?
uuencode
and downvote it, since it's already 2016 AD. :) – Satō Katsura Sep 10 '16 at 14:28systemd(8)
. Anyway, you still have plan B: read the RFC and create a valid message. It isn't that hard for the simplest cases. You need to generate a boundary and a few headers. Mutt requires the installation of a Sendmail compatible SMTP agent to send emails - Mutt can usessmtp
. You just need to configure it. why not just interact with the SMTP agent directly? - Because then you'd also need to read the SMTP RFC, and apply it correctly? – Satō Katsura Sep 10 '16 at 16:51uuencode
does. For example, this answer uses it to help create a MIME compliant email: http://stackoverflow.com/a/11725308/6627890 . Unfortunately, I just created a test script using that answer and it didn't work at all; in the received test email, the body's text has disappeared and the raw text representing the attachment was pasted into the body. – XJDHDR Sep 10 '16 at 17:00uuencode
does. - Then you misunderstand what MIME compliance is about. shrug – Satō Katsura Sep 10 '16 at 17:02uuencode
generates an inline encoding of a file, and was invented back in the dark days before MIME. In such emails there were no body or attachment parts, there was only email. These days we have MIME, and strangely we no longer have body parts (to emails). Rather, emails contain one or more attachments and a mail client is expected to know which text attachment is to be treated as a body and displayed as such. – Chris Davies Sep 10 '16 at 18:05mpack
to send MIME mails over the command line. – Rui F Ribeiro Sep 10 '16 at 21:42mpack
and it was exactly what I needed. Thank you! – XJDHDR Sep 11 '16 at 05:15