On 3/10/21 12:39 PM, Daniel Botting wrote: > 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.
That was my mistake, sorry. > 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] mlist.moderator is already a list so [mlist.moderator] is a list of lists. > #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 You have to import it. You also need to import smtplib. If you do import smtplib then you can do try: smtpObj = smtplib.SMTP('localhost') ... except smtplib.SMTPException: ... Or if you also do from smtplib import SMTPException you can write the except clause as except SMTPException: There is no magic by which Python knows the names of things other than builtins (see sections 2 - 6 at <https://docs.python.org/2.7/library/index.html>). You have to import them or define them. -- Mark Sapiro <m...@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan ------------------------------------------------------ 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/