Problem sending SMTP Email - Raspberry Pi Forums


i have been trying send email using these codes.
receive following error code occasionally:

[errno -5] no address associated hostname

idea why? success rate of sending email 0-20%.
there socket or timeout error? or??
please advise. many thanks.

code: select all

#!/usr/bin/env python import smtplib time import sleep  gmail_user = 'xxx@gmail.com' gmail_pass = 'yyy' smtp_server = 'smtp.gmail.com' email_address1 = 'zzz@gmail.com' smtp_port = 587  def send_email(recipient, subject, text):         try:                    smtpserver = smtplib.smtp(smtp_server, smtp_port)                 smtpserver.ehlo()                 smtpserver.starttls()                 smtpserver.ehlo()                 smtpserver.login(gmail_user, gmail_pass)                 header = 'to:' + recipient + '\n' + 'from: ' + gmail_user                 header = header + '\n' + 'subject:' + subject + '\n'                 msg = header + '\n' + text + ' \n\n'                 smtpserver.sendmail(gmail_user, recipient, msg)                 smtpserver.quit()                 print ("successfully sent")         except exception, msg:                 print ("failure:  " + str(msg))         cnt = 0 while (cnt < 10):         send_email(email_address1, 'test email', 'thank you')         cnt = cnt + 1         sleep(5) 

are intending send 10 mails in rapid succession , sleep 5 seconds?
while loop seems doing.

wouldn't surprised if gmail did reject being kind of spam or abuse. not have idea how deal deal such things.

happens when send mail once?


raspberrypi



Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code