Changeset 2795

Show
Ignore:
Timestamp:
03/15/06 08:01:21 (19 years ago)
Author:
jerome
Message:

Now uses MIME to send mail, like it was alredy done in cupspykota.

Location:
pykota/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/NEWS

    r2791 r2795  
    2222PyKota NEWS : 
    2323        
     24    - 1.24alpha18 (2006-03-15) : 
     25     
     26        - Now uses MIME encapsulation for email messages to avoid 
     27          some problems with 8 bits messages being rejected. 
     28           
    2429    - 1.24alpha17 (2006-03-06) : 
    2530     
  • pykota/trunk/pykota/tool.py

    r2793 r2795  
    313313                admin = self.config.getAdminMail("global") # Nice trick, isn't it ? 
    314314                server = smtplib.SMTP(self.smtpserver) 
    315                 server.sendmail(admin, [admin, crashrecipient], \ 
    316                                        "From: %s\nTo: %s\nCc: %s\nSubject: PyKota v%s crash traceback !\n\n%s" % \ 
    317                                        (admin, crashrecipient, admin, __version__, fullmessage)) 
     315                msg = MIMEText(fullmessage, _charset=self.charset) 
     316                msg["Subject"] = str(Header("PyKota v%s crash traceback !" \ 
     317                                        % __version__, charset=self.charset)) 
     318                msg["From"] = admin 
     319                msg["To"] = crashrecipient 
     320                msg["Cc"] = admin 
     321                server.sendmail(admin, [admin, crashrecipient], msg.as_string()) 
    318322                server.quit() 
    319323        except : 
     
    428432    def sendMessage(self, adminmail, touser, fullmessage) : 
    429433        """Sends an email message containing headers to some user.""" 
    430         if "@" not in touser : 
    431             touser = "%s@%s" % (touser, self.maildomain or self.smtpserver) 
    432434        try :     
    433435            server = smtplib.SMTP(self.smtpserver) 
     
    436438        else : 
    437439            try : 
    438                 server.sendmail(adminmail, [touser], "From: %s\nTo: %s\n%s" % (adminmail, touser, fullmessage)) 
     440                server.sendmail(adminmail, [touser], fullmessage) 
    439441            except smtplib.SMTPException, answer :     
    440442                for (k, v) in answer.recipients.items() : 
     
    445447        """Sends an email message to a user.""" 
    446448        message += _("\n\nPlease contact your system administrator :\n\n\t%s - <%s>\n") % (admin, adminmail) 
    447         self.sendMessage(adminmail, user.Email or user.Name, "Subject: %s\n\n%s" % (subject, message)) 
     449        usermail = user.Email or user.Name 
     450        if "@" not in usermail : 
     451            usermail = "%s@%s" % (usermail, self.maildomain or self.smtpserver or "localhost") 
     452        msg = MIMEText(message, _charset=self.charset) 
     453        msg["Subject"] = str(Header(subject, charset=self.charset)) 
     454        msg["From"] = adminmail 
     455        msg["To"] = usermail 
     456        self.sendMessage(adminmail, usermail, msg.as_string()) 
    448457         
    449458    def sendMessageToAdmin(self, adminmail, subject, message) : 
    450459        """Sends an email message to the Print Quota administrator.""" 
    451         self.sendMessage(adminmail, adminmail, "Subject: %s\n\n%s" % (subject, message)) 
     460        if "@" not in adminmail : 
     461            adminmail = "%s@%s" % (adminmail, self.maildomain or self.smtpserver or "localhost") 
     462        msg = MIMEText(message, _charset=self.charset) 
     463        msg["Subject"] = str(Header(subject, charset=self.charset)) 
     464        msg["From"] = adminmail 
     465        msg["To"] = adminmail 
     466        self.sendMessage(adminmail, adminmail, msg.as_string()) 
    452467         
    453468    def _checkUserPQuota(self, userpquota) :             
  • pykota/trunk/pykota/version.py

    r2791 r2795  
    2222# 
    2323 
    24 __version__ = "1.24alpha17_unofficial" 
     24__version__ = "1.24alpha18_unofficial" 
    2525 
    2626__doc__ = "PyKota : a complete Printing Quota Solution for CUPS."