While sending mail I want to include signature inline to each of the mail. The whole signature include an image with few links. Its somewhat like this:http://imgur.com/ZqV3HxG
Below is the code :
import smtplib,ssl
import email.utils
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from xlrd import open_workbook, xldate_as_tuple
from datetime import date
import os
input_file = “sample.xlsx”
context = ssl.create_default_context()
server = smtplib.SMTP_SSL(host=‘smtp.gmail.com’,port= 465,context=context)
server.login(‘username@gmail.com’,‘password’)
subject = “Test Subject”
fromaddr=‘username@gmail.com’
with open_workbook(input_file) as workbook:
worksheet = workbook.sheet_by_name(‘sample1’)
for row_index in range(1, worksheet.nrows):
name = worksheet.cell_value(row_index, 0)
toaddr = worksheet.cell_value(row_index, 1)
msg = MIMEMultipart()
text = "Dear "+str(name)+ ",\nThanks for your valuable sugestions. \nSincere Regards,\n"+"""\
<html>
<body>
<p>a href="https://www.python.org/">Python</a></p>
</body>
</html>
"""
msg['To'] = toaddr
msg['From'] = email.utils.formataddr(('myName', fromaddr))
msg['Subject'] = subject
part1 = MIMEText(text)
#part2 = MIMEText(html, 'html')
msg.attach(part1)
#msg.attach(part2)
server.sendmail(fromaddr, toaddr, msg.as_string())
print(“Emails sent successfully”)
server.quit()
I’ve tried to include html part, but its not working. Any suggestions?