Я не понимаю, почему я посылаю пустое сообщение с моим кодом. Нет сообщений, без темы.Пустое сообщение отправить с smtplib
Я читал много примеров, но у меня всегда была одна и та же проблема. Я даже не понял, почему иногда нам приходится использовать .close() или .quit()
Наконец-то я потерян, мне нужен ваш свет. См. Ниже мой последний код.
### SEND EMAIL ###
sender = "[email protected]"
destination = user.email
html = ''
text = ''
if country is 'USA':
text = "your pin code:"+pin
html = """\
<html>
<head></head>
<body>
<p>
Hi!<br>
How are you?<br>
Here is the pin code you wanted: ""+pin""
</p>
</body>
</html>
"""
if country is 'CAN':
text = "ton code pin:"+pin
html = """
<html>
<head></head>
<body>
<p>
Bonjour !<br>
Ici le code pin: ""+pin""
</p>
</body>
</html>
"""
try:
msg = MIMEMultipart('alternative')
if country is 'USA':
msg['Subject'] = "Registration"
if country is 'CAN':
msg['Subject'] = "Inscription"
msg['From'] = sender
msg['To'] = destination
part1 = MIMEText(text, 'plain', 'utf-8')
part2 = MIMEText(html, 'html', 'utf-8')
msg.attach(part1)
msg.attach(part2)
usernameEmail = '[email protected]'
passwordEmail = '123456'
conn = smtplib.SMTP('smtp.myserver.com')
conn.set_debuglevel(True) # Debug
conn.login(usernameEmail, passwordEmail)
try:
conn.sendmail(sender, destination, msg.as_string())
finally:
conn.quit()
except SMTPException:
msg = 'unable to mail'
code = '503'
return {
"error": {
"message": msg,
"type": "myserverException",
"code": code
}
}
А я - манекен. Ты прав. Но мне интересно, когда используете .close() или quit() – OlZ