On Mon, May 15, 2023 at 2:57 PM Tim Moody <t...@timmoody.com> wrote: > > I'd like to send an email from a python3 process on a wmcs VPS to report > errors. > > I looked at https://wikitech.wikimedia.org/wiki/Help:Email_in_Cloud_VPS but > could use some help. > > sudo echo "Subject: sendmail test2" | /usr/sbin/sendmail -v <myemail> works.
The `sudo` here does nothing useful. It is bound to the `echo` invocation and not the `sendmail` one. > When I try to send the equivalent from python smtplib I get a 221 error > message. 221 is the SMTP status code for closing connection/goodbye. This isn't specifically an error, instead it means that the SMTP server has decided to end the session. * Are there other status codes you see from your attempted python code prior to the 221? * What SMTP server are you connecting to? * Is the python code available somewhere for review? Here is a quick example of sending email using Python 3.9 and smtplib from inside Toolforge: $ become bd808-test -- webservice python3.9 shell -- python3.9 >>> import smtplib >>> import ssl >>> context = ssl.create_default_context() >>> server = smtplib.SMTP("mail.tools.wmcloud.org", 587) >>> server.starttls(context=context) (220, b'TLS go ahead') >>> server.sendmail("bd808-test.maintain...@toolforge.org", "bd...@wikimedia.org", """Subject: smtplib example from Toolforge ... ... Hello world. ... --- ... Bryan""") {} >>> server.quit() (221, b'mail.tools.wmcloud.org closing connection') Things would typically look similar from a Cloud VPS project. The major change would be to use mx-out03.wmcloud.org or mx-out04.wmcloud.org as your outbound SMTP service. There is a bit more complication in using TLS as well due to the x509 certificate being a bit of a mess (bad subject and expired): $ ssh devportal-demo01.devportal.eqiad1.wikimedia.cloud $ python3.9 >>> import smtplib >>> import ssl >>> context = ssl.create_default_context() >>> context.check_hostname = False >>> context.verify_mode = ssl.CERT_NONE >>> server = smtplib.SMTP("mx-out03.wmcloud.org", 25) >>> server.starttls(context=context) (220, b'TLS go ahead') >>> server.sendmail("bd...@wikimedia.org", "bd...@wikimedia.org", """Subject: smtplib example from Cloud VPS ... ... Hello world. ... --- ... Bryan""") {} >>> server.close() I hope that helps a bit. Bryan -- Bryan Davis Technical Engagement Wikimedia Foundation Principal Software Engineer Boise, ID USA [[m:User:BDavis_(WMF)]] irc: bd808 _______________________________________________ Wikitech-l mailing list -- wikitech-l@lists.wikimedia.org To unsubscribe send an email to wikitech-l-le...@lists.wikimedia.org https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/