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. :)systemd(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?uuencode
does. For example, this answer uses it to help create a MIME compliant email: 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.uuencode
does. - Then you misunderstand what MIME compliance is about. shrug