Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to send email with smtplib and MIMEText?
    text
    copied!<p>I'm looking for an answer for some days and untill now I just didn't solve my problem. All I want is to send a simple email message from my program if an error occure. I'm using the gmail server to do that, and it actually sends the email, but the message of the email doesn't appear. Here's the code:</p> <pre><code>def accept(self): HOST = 'smtp.gmail.com' PORT = '587' user = '***********@gmail.com' senha = '***********' servidor = smtplib.SMTP() servidor.connect(HOST, PORT) servidor.ehlo() servidor.starttls() servidor.ehlo() servidor.login(user, senha) assunto = 'Relatorio de Erro' para = '**************@hotmail.com' endereco = self.nemail.text() de = str(endereco) texto = self.message.toPlainText() textos = Message(texto) corpo = MIMEText(textos) corpo['From'] = de corpo['To'] = user corpo['Subject'] = assunto servidor.set_debuglevel(1) servidor.sendmail(user, para, corpo.as_string()) servidor.quit </code></pre> <p>This raises an error on the MIMEText. Says that can't convert MIMEText to str. The I tried another version, just for test. Sending a simple string:</p> <pre><code>def accept(self): HOST = 'smtp.gmail.com' PORT = '587' user = '*************@gmail.com' senha = '************' servidor = smtplib.SMTP() servidor.connect(HOST, PORT) servidor.ehlo() servidor.starttls() servidor.ehlo() servidor.login(user, senha) assunto = 'Relatorio de Erro' para = '*********@hotmail.com' servidor.set_debuglevel(1) servidor.sendmail(user, para, assunto) servidor.quit() </code></pre> <p>The email comes to the right inbox, but it has no message, nothing. I searched a lot, I'd read the docs, I tried it so much that I don't even know what I'm doing. It looks like I'm almost getting. Can someone help me?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload