0

I am not able to send the mail without password authentication in python.Its printing the last message but mail is not sent.Below is the code that i am using.Anyone please help i am stuck because of this. Thanks in advance.

import smtplib

fromaddr = 'xyz@gmail.com'
toaddrs  = ['abc@gmail.com']
msg = '''
    From: {fromaddr}
    To: {toaddr}
    Subject: 'testing'     
    This is a test 
    .
'''

msg = msg.format(fromaddr =fromaddr, toaddr = toaddrs[0])

server = smtplib.SMTP("gmail-smtp-in.l.google.com:25")
server.starttls()
server.ehlo("example.com")
server.mail(fromaddr)
server.rcpt(toaddrs[0])
server.data(msg)
server.quit/close()
print("mail sent")  
Navneet
  • 45
  • 5
  • if you can"t send without authentication, why not try with authentication? – Maarten Fabré May 30 '17 at 13:54
  • Thanks for reply Maarten. Its working by password authentication but i do not want to expose password in the script that is why i m looking for other options. – Navneet May 30 '17 at 14:48
  • You could put the password in a configuration file. Btw, you can use a `with`-statement for the smtplib, like in the example on the [documentation](https://docs.python.org/3.5/library/smtplib.html) – Maarten Fabré Jun 10 '17 at 22:47

0 Answers0