im just trying to make a simple code that sends emails to my clients with a PDF file attached, it was working on June when I created the version 1.0, now I'm recreating using a GUI and the sender is now broken
import smtplib
from email.message import EmailMessage
def Enviar_emails(email,senha, email_cli, pdf_cli):
server_type = 'smtp.office365.com'
port = 587
try:
print("iniciando envio de emails")
msg = EmailMessage()
msg['From'] = email
msg.set_content("Aqui estão as novas atualizações em relação a mudança do aluguel de acordo com as normas IGP-M.")
msg["To"] = email_cli
msg["Subject"] = "Atualização do valor de custo mensal da propriedade."
fileToSend = pdf_cli
emailToSend = email_cli
print(emailToSend)
contFile = open(f'.\\pdf\\{fileToSend}', 'rb')
cont = contFile.read()
msg.add_attachment(cont, maintype='application', subtype='pdf', filename=fileToSend)
server = smtplib.SMTP(server_type, port)
server.starttls()
server.login(email, senha)
server.send_message(msg)
msg.clear_content()
except Exception as e:
print(f"Error: {e}")
Enviar_emails('[email protected]', 'app_password', '[email protected]','fileToSend.pdf')
When I tried this code I received this error:
(535, b'5.7.139 Authentication unsuccessful, basic authentication is disabled. [CP5P284CA0198.BRAP284.PROD.OUTLOOK.COM 2024-12-12T23:57:36.327Z 08DD19E380D79708]')
I believe that the error is on or the Microsoft outlook account, or on the smtplib config
the account was created today just to test the smtplib and make this code work