G Suite smtplib.SMTPAuthenticationError: (535, b’5.7.8 Username and Password not accepted.) send email through python

gsuite setting 에서 유저별로 apps manage하게 해주기

smtplib.SMTPAuthenticationError: (535, b’5.7.8 Username and Password not accepted.)

 

email  sender test code 만드는 중 보내는 사람 개인  gmail account에서 회사메일 gsuite domain 계정으로 보내려고 하니 Error 발생.

 

에러 메시지로 구글에서 검색하면 아래의 내용이 뜬다.

https://stackoverflow.com/questions/17759860/python-2-smtpserverdisconnected-connection-unexpectedly-closed

아무래도 나는 여기에 해당이 안되는 것 같고..

 

뭐라고 검색해야 이 문제를 해결할 수 있을까?

 

 

먼저 숙지 해야할 사항에는 아래와 같다.

https://support.google.com/accounts/answer/3466521

-> gmail account에 app pwd를 설정해서 내 구글 account가 아닌 gmail에만 접근이 가능하단 사실을 알아야한다.

 

 

설정해야하는 이슈는

  1. gmail에 접속 가능한 app pwd 설정
  2. Gsuite 관리자 설정에서 1번 허용해주기

 

 

우선 1번부터

https://myaccount.google.com/u/0/security?pageId=none

에서 2 step verification 을 On  시키고, app password를 추가한다. 이 때 생성된 비번은 16자리 코드로 아래의 코드 중 pwd에 위치한다.

smtp.login(email, pwd)

스크린샷 2019-09-11 오전 3.02.39

 

그 다음 2번

admin.google.com  관리 콘솔에 접속 후

보안>기본설정으로 사용자 수준에서 아래 그림처럼 app접근을 허용하는 걸로 수정하고 

스크린샷 2019-09-11 오전 3.07.15

오른쪽 하단에 submit

더 자세한 것은 아래의 링크를 확인하면 된다.

https://support.google.com/a/answer/6260879?hl=ko

 

 

이렇게 하고 소스코드 실행하면 성공!