So I'll try to explain this the best I can. The task I have at hand is to gather data from a database and to put that information into a custom coded/formatted HTML/CSS email.
The error I get when running this code is: TypeError: Can't convert 'list' object to 'str' implicitly. The data I am getting from the database bring back a result of 8 strings within a list in each section so I know why that error is coming back. I'm just not too sure how to get around it to be able to embed all the data within an email automatically and send it with proper formatting for email like this.
import smtplib
import sys
import sqlite3
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
DATABASE = 'Blocs.db'
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
print("Getting blocs from server...")
conn = sqlite3.connect(DATABASE)
cur = conn.cursor()
cur.execute("SELECT weburl FROM Blocs")
weburl_data = cur.fetchall()
cur.execute("SELECT imgurl FROM Blocs")
imgurl_data = cur.fetchall()
cur.execute("SELECT title FROM Blocs")
title_data = cur.fetchall()
cur.execute("SELECT notes FROM Blocs")
notes_data = cur.fetchall()
conn.commit()
conn.close()
from_email = "test@email.com"
from_pwd = "Password"
to_email = "sendHere@email.com"
msg = MIMEMultipart('html')
msg['Subject'] = "Test SMTPlib Message"
msg['From'] = "test@email.com"
msg['To'] = "sendHere@email.com"
firstHTML = '<html> <head></head> <body><table> <tr>'
bloc_one = weburl_data
secondHTML = '</tr></table></body></html>'
new_html = firstHTML + bloc_one + secondHTML
msg.attach(MIMEText(new_html, 'html'))
print(msg)
mail = smtplib.SMTP('outlook.office365.com', 587)
mail.ehlo()
mail.starttls()
mail.login("test@email.com", "Password")
mail.sendmail("test@email.com", "sendHere@email.com", msg.as_string())
print("email sent")
mail.quit()