Open blu-IT opened 8 years ago
OK, after doing some additional research I found a solution for using aexternal smtp-host with ssl/starttls:
MAIL_SMTP_SERVER = 'smtp.myserver.de'
I added these two lines at the code after line 521/522
s.starttls() # needed if SSL/StartTLS is required (Port 465)
s.login('myuser', 'mypassword') # insert your e-mailuseraccount/password here
So code from line 519 looks like this now:
# note if using an ipaddress in MAIL_SMTP_SERVER,
# then may require smtplib.SMTP(MAIL_SMTP_SERVER, local_hostname="localhost")
s = smtplib.SMTP(MAIL_SMTP_SERVER)
s.starttls() # needed if SSL/StartTLS is required (Port 465)
s.login('myuser', 'mypassword') # insert your e-mailuseraccount/password here
s.sendmail(MAIL_FROM_ADDR, to.split(','), msg.as_string())
s.quit()
Added my modifications to the code. I would like to pull..
That's indeed needed if you are requires to authenticate to connect to an SMTP with that requirement. Have you tried using the password encryption mechanism built in to try to obfuscate the password information?
Hi, I'm not quite shure which password encryption mechanism you mean. The one for starting the script without an user action (yes - it works) or for encryption of the mailuseraccount (no - is there any mechanism/way)? As my problem is/was related to mail sending (SSL/StartTLS), I could fix that with the code I posted before. Still would like to see it in the future code ;-)
Regards
For now, to clarify, we do not have the means to handle SMTP password authentication. We can put it on the long-term desired features list. Looksclike you'd need to use an s.login mechanism, such as discussed here: http://stackoverflow.com/questions/14196581/python-smtp-requires-authentication
The more conventional code would look something like this. Port 587 is preferred for SMTP/TLS authentication:
server = smtplib.SMTP(MAIL_SMTP_SERVER:587) or server = smtplib.SMTP(MAIL_SMTP_SERVER,587) server.ehlo() server.starttls() server.login(username, password)
and so on.
In any case, it's on the list of things to strongly consider building in since it's not hard to do, but ould take some work to incorporate the logic to support both it and the conventional means with minimal code disruption. Different mail gateways also require different username conventions, some, for example, require the domain be included, some the email address, others just th esimple username, etc. so there is more to go wrong when setting things up.
Hello,
I tried different configurations for sending automated notification after backup.
When configuring
MAIL_SMTP_SERVER = 'smtp.myserver.de'
then I get
smtplib.SMTPSenderRefused: (550, '5.7.1 Authentication Required','')
and when I configure
MAIL_SMTP_SERVER = 'localhost'
(with working ssmtp.config) there is an error like "Network is unreachable".
So where do I set config parms for authentication with external smtp-hosts or how to get in touch with my local ssmtp-host in a working manner?
Thanks!