This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vinay.sajip
Recipients norbidur, vinay.sajip
Date 2010-08-22.18:34:05
SpamBayes Score 1.9731794e-10
Marked as misclassified No
Message-id <1282502048.67.0.744692066079.issue9208@psf.upfronthosting.co.za>
In-reply-to
Content
SMTPHandler provides an implementation for the simplest/most common case. Full support for encoding in emails is likely to be application-specific, i.e. no one-size-fits-all can be easily specified. For example, different encodings could be used for headers, subject and body - say, quoted-printable for the body and base64 for the subject. Unfortunately, support for quoted-printable requires a global state change, see for instance

http://radix.twistedmatrix.com/2010/07/how-to-send-good-unicode-email-with.html

so it seems not to be a good idea to implement in the logging package itself.

I would suggest implementing a handler which subclasses SMTPHandler and does the appropriate formatting as per (for example) the above post. To facilitate this, I coukd add two methods to SMTPHandler:

class SMTPHandler(logging.Handler):
    def prepareEmail(self, record):
        """
        Prepare a record for emailing, including setting up mail
        headers doing all necessary encodings. Return a value
        suitable for passing to the sendEmail method.

        The default implementation will assume all-ASCII content
        for headers and body, do no special encoding, and return a
        string.
        """

    def sendMail(self, smtp, msg):
        """
        Send a message via the provided SMTP instance.

        The default implementation will call smtplib.sendmail(),
        passing the result from the prepareEmail method.
        """

I'm not yet sure if this would meet all use cases.

Marking as pending, awaiting feedback. Will close in a couple of weeks if no feedback received.
History
Date User Action Args
2010-08-22 18:34:08vinay.sajipsetrecipients: + vinay.sajip, norbidur
2010-08-22 18:34:08vinay.sajipsetmessageid: <1282502048.67.0.744692066079.issue9208@psf.upfronthosting.co.za>
2010-08-22 18:34:06vinay.sajiplinkissue9208 messages
2010-08-22 18:34:05vinay.sajipcreate