Reputation: 35
What I am doing is taking information from a web page and attempting to put it into an e-mail in a format like: First Name: first \n#first is a variable Last Name: last #last is a variable
Below is my code:
import smtplib
import base64
from email.MIMEMultipart import MIMEMultipart
from email.mime.text import MIMEText
msg = MIMEMultipart('relative')
msg['Subject'] = 'Confirmation E-Mail'
msg['From'] = "none"
msg['To'] = email
text1 = "First Name: ", first_name, "<br>Last Name: ", last_name
part1 = MIMEText(text1, 'html')
s = smtplib.SMTP('localhost')
s.sendmail(email, email, msg.as_string())
s.quit()
first_name and last_name are pulled from the web page!
Upvotes: 1
Views: 6642
Reputation: 4742
MIMEText takes a string as its first argument. You're creating text1 as a tuple. You need something more like
"First Name: %s\nLast Name: %s" % (first_name, last_name)
Upvotes: 4
Reputation: 7164
you need to attach part1 to msg:
msg.attach(part1)
you can also find a good example of how to send a multipart email message in the Python Documenation
Upvotes: 1