Hi Mark,
Thank you, much appreciated.
I've got it working and progressed a little further ;)
["pwgen", "-sB", "15", "1"]).strip())
I had to remove the very end closing bracket, it was causing a syntax error.
I then encountered a Errno 2 error no such file, which I tracked down to
the fact this was a new test server due to mail not being received to
lists and I didn't have pwgen installed.
I then managed to get it to email me either directly for each occurence
of the password being changed if I just put in my email address directly
or if one moderator is set, the issue comes that if I have more than one
moderator it's mangling the message:
print('%s moderator password changed to %s' %
(mlist.real_name, newpassword))
print(mlist.moderator)
sender = 'root@host fqdn'
receivers = [mlist.moderator]
#receivers = ['my.directem...@domain.co.uk']
message = """ Daniel on list-test4
"""
try:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message)
print ("Successfully sent email")
except SMTPException:
print ("Error: unable to send email")
mlist.Save()
If it can't send email because of this issue the traceback advises (been
trying to figure this out as well):
NameError: global name 'SMTPException' is not defined
I did some debugging:
print.moderator displays:
['moderat...@domain.co.uk', 'moderat...@domain.co.uk']
Exim4 mainlog file is showing:
2021-03-10 20:24:55 SMTP syntax error in "rcpt
TO:<moderat...@domain.co.ukmoderat...@domain.co.uk>" H=localhost (box
fqdn) [127.0.0.1] malformed address: @domain.co.uk> may not follow
<moderat...@domain.co.ukmoderator2
I've been trying to work out to get a space to be added, as that looks
like the issue to me?
Finally in regards to pythontutor, very helpful thank you. My thirteen
year old son is also taking an interest in Python recently after doing a
bit at school, we are learning together :)
Many thanks
Daniel
On 08/03/2021 18:04, Mark Sapiro wrote:
You want something like this for the script
------------------------------------------------------
import subprocess
from Mailman.Utils import sha_new
def change_moderator_password2(mlist, moderator):
if not mlist.Locked():
mlist.Lock()
try:
if moderator in mlist.moderator:
newpassword = subprocess.check_output(
["pwgen", "-sB", "15", "1"]).strip())
mlist.mod_password = sha_new(newpassword).hexdigest()
print('%s moderator password changed to %s' %
(mlist.real_name, newpassword))
mlist.Save()
else:
print('%s not found in %s moderator' %
(moderator, mlist.real_name))
except subprocess.CalledProcessError as e:
print("password not changed for %s: %s\n%s" %
(mlist.real_name, moderator, e.output))
finally:
mlist.Unlock()
--
Daniel Botting
Systems Administrator
Codethink Ltd.
3rd Floor Dale House,
35 Dale Street,
Manchester, M1 2HF
United Kingdom
http://www.codethink.co.uk/
We respect your privacy. See https://www.codethink.co.uk/privacy.html
------------------------------------------------------
Mailman-Users mailing list -- mailman-users@python.org
To unsubscribe send an email to mailman-users-le...@python.org
https://mail.python.org/mailman3/lists/mailman-users.python.org/
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: https://www.mail-archive.com/mailman-users@python.org/
https://mail.python.org/archives/list/mailman-users@python.org/