Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email module in python 3

Tags:

python

email

So I'm following a tutorial to send email in python, the problem is that it was written for python 2 not python 3(which is what I have). So here's what I'm trying to get an answer what is the module for email in python 3? the specific module I'm trying to get is is:

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

I also have a feelling that when I get down to this module there will be an error (haven't got there yet because of the module above giving error

import smtp

Here is the script:

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

fromaddr = ("[email protected]")
toaddr = ("[email protected]")
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("[email protected]", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
text = msg.as_string()
sender.sendmail(fromaddr, toaddr, text)
like image 881
raspberry.pi Avatar asked Jul 02 '13 17:07

raspberry.pi


1 Answers

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

By the way here are some mistakes in your code:

fromaddr = "[email protected]" # redundant parentheses
toaddr = "[email protected]" # 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("[email protected]", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX") # on most SMTP servers you should remove domain name(`@mchsi.com`) here
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text) # it's not `sender`
like image 179
xmcp Avatar answered Oct 18 '22 02:10

xmcp