diff options
-rw-r--r-- | cnf/make.conf | 1 | ||||
-rw-r--r-- | pym/portage_mail.py | 43 |
2 files changed, 27 insertions, 17 deletions
diff --git a/cnf/make.conf b/cnf/make.conf index 2180cd955..8f9650ee7 100644 --- a/cnf/make.conf +++ b/cnf/make.conf @@ -339,6 +339,7 @@ PORTAGE_ELOG_CLASSES="warn error log" # user: username for smtp auth (defaults to none) # passwd: password for smtp auth (defaults to none) # mailserver: smtp server that should be used to deliver the mail (defaults to localhost) +# alternatively this can also be a the path to a sendmail binary if you don't want to use smtp # port: port to use on the given smtp server (defaults to 25, values > 100000 indicate that starttls should be used on (port-100000)) # Examples: #PORTAGE_ELOG_MAILURI="root@localhost localhost" (this is also the default setting) diff --git a/pym/portage_mail.py b/pym/portage_mail.py index 9588ea210..37bd11b64 100644 --- a/pym/portage_mail.py +++ b/pym/portage_mail.py @@ -3,7 +3,7 @@ # Distributed under the terms of the GNU General Public License v2 # $Id: portage.py 3483 2006-06-10 21:40:40Z genone $ -import portage_exception, socket, smtplib +import portage_exception, socket, smtplib, os from email.MIMEText import MIMEText as TextMessage from email.MIMEMultipart import MIMEMultipart as MultipartMessage from email.MIMEBase import MIMEBase as BaseMessage @@ -36,12 +36,13 @@ def send_mail(mysettings, message): mymailpasswd = "" myrecipient = "root@localhost" - # Syntax for PORTAGE_LOG_MAILURI (if defined): + # Syntax for PORTAGE_ELOG_MAILURI (if defined): # adress [[user:passwd@]mailserver[:port]] # where adress: recipient adress # user: username for smtp auth (defaults to none) # passwd: password for smtp auth (defaults to none) # mailserver: smtp server that should be used to deliver the mail (defaults to localhost) + # alternatively this can also be the absolute path to a sendmail binary if you don't want to use smtp # port: port to use on the given smtp server (defaults to 25, values > 100000 indicate that starttls should be used on (port-100000)) if " " in mysettings["PORTAGE_ELOG_MAILURI"]: myrecipient, mymailuri = mysettings["PORTAGE_ELOG_MAILURI"].split() @@ -59,21 +60,29 @@ def send_mail(mysettings, message): mymailhost = myconndata else: myrecipient = mysettings["PORTAGE_ELOG_MAILURI"] - try: - myfrom = message.get("From") + + # user wants to use a sendmail binary instead of smtp + if mymailhost[0] == os.sep and os.path.exists(mymailhost): + fd = os.popen(mymailhost+" "+myrecipient, "w") + fd.write(mymessage.as_string()) + if fd.close() != None: + sys.stderr.write("!!! %s returned with a non-zero exit code. This generally indicates an error.\n" % mymailhost) + else: + try: + myfrom = message.get("From") - if int(mymailport) > 100000: - myconn = smtplib.SMTP(mymailhost, int(mymailport) - 100000) - myconn.starttls() - else: - myconn = smtplib.SMTP(mymailhost, mymailport) - if mymailuser != "" and mymailpasswd != "": - myconn.login(mymailuser, mymailpasswd) - myconn.sendmail(myfrom, myrecipient, message.as_string()) - myconn.quit() - except smtplib.SMTPException, e: - raise portage_exception.PortageException("!!! An error occured while trying to send logmail:\n"+str(e)) - except socket.error, e: - raise portage_exception.PortageException("!!! A network error occured while trying to send logmail:\n"+str(e)+"\nSure you configured PORTAGE_ELOG_MAILURI correctly?") + if int(mymailport) > 100000: + myconn = smtplib.SMTP(mymailhost, int(mymailport) - 100000) + myconn.starttls() + else: + myconn = smtplib.SMTP(mymailhost, mymailport) + if mymailuser != "" and mymailpasswd != "": + myconn.login(mymailuser, mymailpasswd) + myconn.sendmail(myfrom, myrecipient, message.as_string()) + myconn.quit() + except smtplib.SMTPException, e: + raise portage_exception.PortageException("!!! An error occured while trying to send logmail:\n"+str(e)) + except socket.error, e: + raise portage_exception.PortageException("!!! A network error occured while trying to send logmail:\n"+str(e)+"\nSure you configured PORTAGE_ELOG_MAILURI correctly?") return |