Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6476735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:51:42+00:00 2026-05-25T06:51:42+00:00

As you know, python smtplib has a debug level.When I set it a true

  • 0

As you know, python smtplib has a debug level.When I set it a true param, it will print some send information.
The problem is, I try to get the debug info to log into a file, but They just stay on my cmd console.
How can I do to log them?

Info like this:

connect: ('192.168.1.101', 25)
connect: (25, '192.168.1.101')
reply: '220 ESMTP on WinWebMail [3.8.1.3] ready.  http://www.winwebmail.com\r\n'

reply: retcode (220); Msg: ESMTP on WinWebMail [3.8.1.3] ready.  http://www.winw
ebmail.com
connect: ESMTP on WinWebMail [3.8.1.3] ready.  http://www.winwebmail.com
send: 'ehlo [169.254.63.67]\r\n'
reply: '250-SIZE\r\n'
reply: '250 AUTH LOGIN\r\n'
reply: retcode (250); Msg: SIZE
AUTH LOGIN
bla bla bla bla........
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:51:43+00:00Added an answer on May 25, 2026 at 6:51 am

    The smtplib prints directly to stderr, e.g. line 823 in smtplib.py:

    print>>stderr, 'connect fail:', host
    

    You’d have to either monkey patch sys.stderr before you import smtplib or smtplib.stderr before you run your mail code.

    I might also suggest patching smtplib.stderr with a custom object that has a write method to wrap your logging code (if you are using the logging library for instance):

    import logging
    import smtp
    
    class StderrLogger(object):
    
        def __init__(self):
            self.logger = logging.getLogger('mail')
    
        def write(self, message):
            self.logger.debug(message)
    
    org_stderr = smtp.stderr
    smtp.stderr = StderrLogger()
    
    # do your smtp stuff
    
    smtp.stderr = org_stderr
    

    This question contains some useful examples of patching stderr with context managers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that python has a len() function that is used to determine the
Possible Duplicate: Reading/Writing MS Word files in Python I know there are some libraries
I know Python, but what is Jython? When will I need Jython? What are
I know python functions are virtual by default. Let's say I have this: class
We know that Python provides a lot of productivity over any compiled languages. We
I know with python and a couple other languages there is a way to
I know of python -c '<code>' , but I'm wondering if there's a more
Does anyone know of a Python equivalent for FMPP the text file preprocessor? Follow
I know there is a method for a Python list to return the first
Does anyone know of a FOSS Python lib for generating Identicons ? I've looked,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.