Created
October 12, 2016 01:05
-
-
Save philippeoz/cc77951262d06115828d1e64ad205bbd to your computer and use it in GitHub Desktop.
Enviando e-mail com anexo(PDF) com 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
from email.MIMEMultipart import MIMEMultipart | |
from email.MIMEBase import MIMEBase | |
from email import Encoders | |
import smtplib | |
############################################# | |
email_login = 'sou.esse.cara@hotmail.com' | |
senha = 'minhaSenha' | |
send_mail_to = 'vou.enviar.pra.esse.cara@gmail.com' | |
caminho_arquivo = '/caminho/para/o/arquivo/na/maquina/nudes.pdf' | |
smtp_server = 'smtp-mail.outlook.com' | |
smtp_server_port = '587' | |
############################################# | |
msg = MIMEMultipart() | |
msg_file = MIMEBase('application', 'pdf') | |
msg_file.set_payload(file(caminho_arquivo).read()) | |
Encoders.encode_base64(msg_file) | |
msg_file.add_header('Content-Disposition', 'attachment', filename='teste.pdf') | |
msg.attach(msg_file) | |
############################################# | |
mailer = smtplib.SMTP(smtp_server, smtp_server_port) | |
mailer.ehlo() | |
mailer.starttls() | |
mailer.login(email_login,senha) | |
mailer.sendmail(email_login, send_mail_to, msg.as_string()) | |
mailer.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bom dia prezado,
òtimo script, porém ao enviar ao receber o e-mail o arquivo pdf em anexo não abre, nem no browser nem no leitor pdf da máquina, faz ideia do porque isso ocorre?