-1
내가 뭘 잘못하고 있니? 너무 단순해야합니다. 실행 후 아무 일도 일어나지 않으며 오류도없고 이메일도 없습니다. 아무것도. Jupyter를 사용하고 있습니다.파이썬을 사용하여 이메일을 보낼 수 없습니다.
def send_email(user, pwd, recipient, subject, body):
import smtplib
gmail_user = '[email protected]'
gmail_pwd = 'pass'
FROM = '[email protected]'
TO = '[email protected]'
SUBJECT = 'Test'
TEXT = 'Hello, this is test email'
# Prepare actual message
message = """From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
try:
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.login(gmail_user, gmail_pwd)
server.sendmail(FROM, TO, message)
server.close()
print ('successfully sent the mail')
except:
print ("failed to send mail")
'try/except'를 제거하고 예외 메시지 – Bahrom
을 보면 함수 정의 일뿐입니다. 이 기능을 실행 했습니까? 즉. 'send_email ("[email protected]", "MyPaSwOrD", "[email protected]", "Money for you", "안녕하세요. 돈이 있습니다.") – furas
@furas thanks. 나는 Python을 처음 사용한다. 네가 한 말대로했다. 하지만 이제는 또 다른 오류가 발생합니다 : 'SMTPAuthenticationError : (535, b'5.7.8 사용자 이름과 비밀번호가 허용되지 않습니다. \ n5.7.8 https://support.google.com/mail/?p=BadCredentials e26sm1483410pfi.10에서 자세히 알아보십시오. - gsmtp ')'. 그러나 또 다른 질문이 있습니다. 당신의 도움을 주셔서 감사합니다. 답을 게시하면 받아 들일 것입니다. – Oleg