1

I am trying to send messages on gmail using python. What I did was following:

>>> import smtplib
>>> session = smtplib.SMTP('smtp.gmail.com',587)

But just after this step, it got stuck i.e. it is not being able to connect to the server. I searched this up on google and found out that gmail actually does a reverse dns lookup and doesn't allow a connection if a domain is not found.
Is there a way to prevent gmail from doing this reverse lookup or something equivalent which helps me in sending messages using python?

Valentin Lorentz
  • 9,556
  • 6
  • 47
  • 69
nishantsingh
  • 4,537
  • 5
  • 25
  • 51
  • This code in this [question](http://stackoverflow.com/questions/22272134/sending-email-does-not-work-when-i-run-the-script-but-line-by-line-it-works-w) and answers show basically how do this. – martineau Mar 09 '14 at 10:37
  • Are you authenticating with your email credentials before sending the mail or just trying to deliver the mail to some random gmail account. Gmail will do `Reverse DNS lookups` only for the latter one. – clement Mar 09 '14 at 10:53
  • @clement89 Authentication is the next step. – nishantsingh Mar 09 '14 at 11:04
  • So if you are authenticating with `SMTP.login(user, password)` before sending mail, Gmail will not be doing Reverse DNS checks. – clement Mar 09 '14 at 11:11
  • This may be helpful: https://stackoverflow.com/questions/9763455/how-to-send-a-mail-directly-to-smtp-server-without-authentication – ρss Mar 09 '14 at 12:55
  • @clement89 Assuming that SMTP is a variable as the format is generally some_Variable.login(_,_), for initialising the variable we first need to run 'some_Variable = smtplib.SMTP("smtp.gmail.com","587")'. – nishantsingh Mar 09 '14 at 14:53

0 Answers0