Email module in python 3

So, I follow the tutorial on sending email in python, the problem is that it was written for python 2 and not python 3 (this is what I have). So here is what I am trying to get the answer, what is the module for email in python 3? the specific module I'm trying to get is:

from email.MIMEMultipart import MIMEMultipart from email.MIMEText import MIMETex 

I also have a feeling that when I proceed with this module, there will be an error (not yet reached because the module above gives an error

 import smtp 

Here is the script:

 from email.MIMEMultipart import MIMEMultipart from email.MIMEText import MIMETex fromaddr = (" XXXXX@mchsi.com ") toaddr = (" XXXX@mchsi.com ") msg = MIMEMultipart msg['From'] = fromaddr msg['To'] = toaddr msg['Subject'] = ("test") body = ("This is a test sending email through python") msg.attach(MIMEText(body, ('plain'))) import smptlib server = smptlib.SMPT('mail.mchsi.com, 456') server.login(" XXXXX@mchsi.com ", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX") text = msg.as_string() sender.sendmail(fromaddr, toaddr, text) 
+4
source share
1 answer
 from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText 

By the way, some errors in your code:

 fromaddr = " XXXXX@mchsi.com " # redundant parentheses toaddr = " XXXX@mchsi.com " # redundant parentheses msg = MIMEMultipart() # not redundant this time :) msg['From'] = fromaddr msg['To'] = toaddr msg['Subject'] = "test" # redundant parentheses body = "This is a test sending email through python" # redundant parentheses msg.attach(MIMEText(body, 'plain')) # redundant parentheses import smtplib # SMTP! NOT SMPT!! server = smtplib.SMTP('mail.mchsi.com', 456) # `port` is an integer server.login(" XXXXX@mchsi.com ", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX") # on most SMTP servers you should remove domain name(`@mchsi.com`) here text = msg.as_string() server.sendmail(fromaddr, toaddr, text) # it not `sender` 
+3
source

Source: https://habr.com/ru/post/1489329/


All Articles