0

Using the ssmtp library and Python (3.10.6), I compose an email message using the following code:

with open(config_filename) as config_file:
                configuration_contents = config_file.read()
                configuration_contents_encoded = configuration_contents.encode()
                version = "0.28"
                subject = f'"TurAlu {version} Configuration file contents"'

                return_status = subprocess.run(["ssmtp", "-s", subject, recipient],\
                                                input=configuration_contents_encoded)

The email is sent, but received with an empty subject line. The "subject" is dropped, it seems.

When I remove the double quotes around the subject, I get the error:

ssmtp: RCPT TO:<TurAlu 0.28 Configuration file contents@noemanetz.de> (501 <TurAlu 0.28 Configuration file=contents@noemanetz.de>: "@" or "." expected after "TurAlu") CompletedProcess(args=['ssmtp', '-s', 'TurAlu 0.28 Configuration file contents', 'info@noemanetz.de'], returncode=1)

and the email is not sent.

khelwood
  • 55,782
  • 14
  • 81
  • 108
Ukimiku
  • 11
  • 1
  • 3
    Did you tried to send a mail in command line (to verify your assumptions)? And did you read the manual page of ssmtp? PS: `-s` is not listed – Giacomo Catenazzi May 20 '23 at 08:19
  • Yes, I tried the command line. The same effect. I didn't know that the option "-s" is not supported. When I omit the "-s" flag, the effect is the same. How else should I do it? Thanks. – Ukimiku May 20 '23 at 08:27
  • Read the docs of ssmtp or ask for help with it in an appropriate place (which isn't here because it isn't a programming tool). – Michael Butscher May 20 '23 at 08:30
  • 1
    https://unix.stackexchange.com/questions/244294/how-to-add-subject-line-when-sending-email-output-of-find-using-ssmtp – STerliakov May 20 '23 at 08:30
  • @Michael Butscher: I was under the impression that everything programming-related was on-topic here. ssmtp in conjunction with Python clearly qualifies as a programming-related question, and in that context, ssmtp is even a programming tool, as it saves me from having to reinvent all the programming behind it, to my mind at least. As an aside, personally, I find your way of reacting to my question kind of impolite, since you use the imperative form, as in "Read the docs..." – Ukimiku May 20 '23 at 08:39
  • You wrote that you had the same effect when calling ssmtp from command line, so the primary problem is not related to Python or programming. I may not be perfectly polite all the time. – Michael Butscher May 20 '23 at 09:45
  • 2
    ssmtp is a low level tool. If you use it, you should understand the email protocol (RFC x822 for many x values), and possibly also some of SMTP (RFC x821). In short: if you have not such knowledge (and requirement): do not use such low level tools. Python has in standard library modules to build email (which you need for such case, and possibly use std interfaces (so command mail/sendmail), and to use SMTP (maybe your computer do not have it, so install one simple SMTP (just for injecting mail). Reconsider your design decisions. – Giacomo Catenazzi May 20 '23 at 10:00
  • @ Giacomo Catenazzi: That's good advice. – Progg May 21 '23 at 05:49

0 Answers0