Thanks. That got me closer. I was not using ssl. When I took your code and
tried to connect to localhost I got

STARTTLS extension not supported by server

when I connected to mx-out03.wmcloud.org I got

(220, b'TLS go ahead')

But when I then do

 server.sendmail("[email protected]", "[email protected]",
... """Subject: smtplib example from Cloud VPS
...   ...
...   ... Hello world.
...   ... ---
...   ... Bryan""")

I get SSL: WRONG_VERSION_NUMBER

In the console /usr/sbin/sendmail -v [email protected] <email.txt

works just fine, so maybe I should just use subproc.

On Mon, May 15, 2023 at 7:44 PM Bryan Davis <[email protected]> wrote:

> On Mon, May 15, 2023 at 2:57 PM Tim Moody <[email protected]> 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("[email protected]",
> "[email protected]", """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("[email protected]", "[email protected]",
> """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 -- [email protected]
> To unsubscribe send an email to [email protected]
> https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/
_______________________________________________
Wikitech-l mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/

Reply via email to