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
I got
(220, b'TLS go ahead')
But when I then do
server.sendmail("noreply(a)wikimedia.org".org", "tim(a)tim.com".com",
... """Subject: smtplib example from Cloud VPS
... ...
... ... Hello world.
... ... ---
... ... Bryan""")
I get SSL: WRONG_VERSION_NUMBER
In the console /usr/sbin/sendmail -v tim(a)tim.com <email.txt
works just fine, so maybe I should just use subproc.
On Mon, May 15, 2023 at 7:44 PM Bryan Davis <bd808(a)wikimedia.org> wrote:
On Mon, May 15, 2023 at 2:57 PM Tim Moody
<tim(a)timmoody.com> wrote:
I'd like to send an email from a python3 process on a wmcs VPS to report
errors.
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.maintainers(a)toolforge.org".org",
"bd808(a)wikimedia.org".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("bd808(a)wikimedia.org".org", "bd808(a)wikimedia.org".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(a)lists.wikimedia.org
To unsubscribe send an email to wikitech-l-leave(a)lists.wikimedia.org
https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/