Created
November 26, 2023 23:26
-
-
Save jurandysoares/886db08c48127d6cac745cc710a8b81f to your computer and use it in GitHub Desktop.
Envia mensagem em texto e hipertexto usando as bibliotecas smtplib, email (interna) e markdown (externa) de Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import markdown | |
remetente = "estudante@jurandy.lab" | |
destinatario = "estudante@jurandy.lab" | |
mensagem = MIMEMultipart("Abracadabra") | |
mensagem["Subject"] = "Abracadabra" | |
mensagem["From"] = remetente | |
mensagem["To"] = destinatario | |
texto_md = """\ | |
Oi, | |
Como estah voce? :+1: | |
Voce ja viu os [novos sites da turma](https://oulu.ifrn.edu.br/sites/turma/tsi-2022-1/)? | |
Visite-os e deixe seus comentarios. | |
- [ ] Gostou? :+1: | |
- [ ] Nao gostou? :-1: | |
Conversamos mais a respeito na hora da aula. | |
**Intel+** | |
""" | |
md = markdown.Markdown(extensions=["pymdownx.emoji", "pymdownx.tasklist"]) | |
texto_html = md.convert(texto_md) | |
print(texto_html) | |
parte1 = MIMEText(texto_md, "plain") | |
parte2 = MIMEText(texto_html, "html") | |
mensagem.attach(parte1) | |
mensagem.attach(parte2) | |
print(mensagem.as_string()) | |
with smtplib.SMTP("localhost") as servidor_smtp: | |
servidor_smtp.sendmail(remetente, destinatario, mensagem.as_string()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment