Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use logging module's SMTPhandler?

Status
Not open for further replies.

bevkpope

Programmer
Apr 30, 2002
15
US
I've done some Python programming, but I still consider myself a Python newbie. I have tried the following on Windows XP and a Mac Pro OS X 10.5.8 system on which I just installed Python 2.6.2.

I was working through Matt Wilson's article on using the logging module:
(If that does not work, then try: ). Everything worked great until his last example. My ISP does not provide e-mail, so I tried using gmail in the line that sets h2. I substituted "mailid" for my actual e-mail address in the following examples; in my test I used my actual e-mail ID.

First attempt:
h2 = logging.handlers.SMTPHandler('smtp.gmail.com', 'mailid@gmail.com', ['mailid@gmail.com'],'ERROR log')
However, that caused the following error to be issued:

Traceback (most recent call last):
File "c:\python26\lib\logging\handlers.py", line 868, in emit
smtp.sendmail(self.fromaddr, self.toaddrs, msg)
File "c:\python26\lib\smtplib.py", line 698, in sendmail
raise SMTPSenderRefused(code, resp, from_addr)
SMTPSenderRefused: (530, '5.7.0 Must issue a STARTTLS command first. 7sm5811915qwb.24', mailid@gmail.com')

I also tried providing my gmail userid/password by adding a 5th, credential, argument, which is a tupple, (username,password) (new in 2.6):
class logging.handlers.SMTPHandler(mailhost, fromaddr, toaddrs, subject[, credentials])

Second attempt:
h2 = logging.handlers.SMTPHandler('smtp.gmail.com', 'mailid@gmail.com', ['mailid@gmail.com'],'ERROR log',('mailid@gmail.com','gmailpassword'))
However, that caused the following error message:

Traceback (most recent call last):
File "c:\python26\lib\logging\handlers.py", line 867, in emit
smtp.login(self.username, self.password)
File "c:\python26\lib\smtplib.py", line 552, in login
raise SMTPException("SMTP AUTH extension not supported by server.")
SMTPException: SMTP AUTH extension not supported by server.

I am able access gmail via Outlook Express, in which I do have to specify my gmail userid/password.

Would someone please point out what I am doing incorrectly?

Thanks,
Bev in TX
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top