0
The code only works when the subject and message(body) of the email are written in a few letters, I have no idea what it might be.
import smtplib
import config
def send_email(subject, msg):
try:
server = smtplib.SMTP('smtp-mail.outlook.com')
server.ehlo()
server.starttls()
server.login(config.EMAIL_ADDRESS, config.EMAIL_PASS)
message = 'Subject: {}\n\n{}'.format(subject, msg)
server.sendmail(config.EMAIL_ADDRESS, config.EMAIL_TEST, message)
server.quit()
print("Envio de email foi concluido")
except:
print("Falha do envio de email")
subject = "Esse é um email teste, não precisa abrir"
msg = "Esse é um email teste obrigado"
send_email(subject, msg)
This is the error that appears:
Traceback (most recent call last):
File "C:/Users/Douglas/PycharmProjects/pythonProject/main.py", line 21, in <module>
send_email(subject, msg)
File "C:/Users/Douglas/PycharmProjects/pythonProject/main.py", line 12, in send_email
server.sendmail(config.EMAIL_ADDRESS, config.EMAIL_TEST, message)
File "C:\Users\Douglas\AppData\Local\Programs\Python\Python38-32\lib\smtplib.py", line 859, in sendmail
msg = _fix_eols(msg).encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode character '\xe3' in position 41: ordinal not in range(128)
Process finished with exit code 1
If too many letters returns some kind of error?
– Woss
if cause, with the "except:" white m will never give to know: remove the
try\except
- let the mistakes happen while Oce develops, then you can know what is happening and tidy up. As it is, you lose all the information.– jsbueno
I made the mistake, it must be something related to subject and message, but I still haven’t found what can be.
– Doug