1

I'm attemping to send email to users however I seem to be tackling a weird error.

        smtp_host = 'smtp.gmail.com'
        smtp_port = 587
        server = smtplib.SMTP()
        #server = smtplib.SMTP_SSL('smtp.googlemail.com', 465)
        server.connect(smtp_host,smtp_port)
        server.ehlo()
        server.starttls()
        server.login('user','pass')

        imap_host = 'imap.gmail.com'
        mail = imaplib.IMAP4_SSL(imap_host)
        send_mail(users,server,email_info, body)

Also I've googled this error and most of the solution appeared to be enabling allow less secure apps. I've done and double checked it. It works when I https://accounts.google.com/DisplayUnlockCaptcha and after some period it again seem to be throwing the error. How do I get rid of this issue permanently. Sending mail script works perfectly fine. However the authentication error throws me off.

 SMTPAuthenticationError: (534, '5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbvR\n5.7.14 4yK7ynhHoSAcv6k15J4tj30IUZbfssVlnb7Z1F1DCrD1P8dQS18UBKqojreAF895k1veXW\n5.7.14 DmHkgXDVCrIlrgi3rYWoxfmpLmdAAX42MC9AL1CvMXdsawyefmjBo-HpnefFk0qIg5CSSe\n5.7.14 LkzXE69W8SGk0hTKQrOXRmImeIeJw2lax0p4Er7orWtD3YI-dpUIvsSUTfVo4Yr66MLUK2\n5.7.14 UY4ZW1CtncZcmgmh518X0Xnv1mXAo> Please log in via your web browser and\n5.7.14 then try again.\n5.7.14  Learn more at\n5.7.14  https://support.google.com/mail/answer/78754 s32sm5373125qtg.2 - gsmtp')
Biplov
  • 1,136
  • 1
  • 20
  • 44

1 Answers1

0

I had the same issue and I needed to do 3 things before it worked (if using a gmail account):

  • You need less secure apps turned ON
  • unlock captcha like you said
  • Finally, I found a google support page telling me I needed to enable IMAP for it to work. Follow the steps in the link and then restart your server.
koopmac
  • 936
  • 10
  • 27