Advertisement
Guest User

Untitled

a guest
Mar 5th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. import smtplib
  2. import sqlite3
  3. from email.message import EmailMessage
  4. from email.utils import make_msgid
  5. # from PIL import Image
  6.  
  7. conn = sqlite3.connect('employees.sqlite')
  8. cursor = conn.cursor()
  9. cursor.execute(
  10.     "SELECT id, LastName, FirstName, Photo from employees WHERE strftime('%m',DOB) = strftime('%m','now') AND  strftime('%d','now') = strftime('%d', DOB)")
  11.  
  12. results = cursor.fetchall()
  13. pic_sql = results[0][3]
  14. print(pic_sql)
  15. conn.close()
  16.  
  17. # Create the base text message.
  18. msg = EmailMessage()
  19. msg['Subject'] = "happy birthday"
  20. msg['From'] = ("zard.41@gmail.com")
  21. msg['To'] = ('s41.blizzard@mail.ru')
  22. msg.set_content("""\
  23. test test
  24. """)
  25.  
  26. # Add the html version.  This converts the message into a multipart/alternative
  27. # container, with the original text message as the first part and the new html
  28. # message as the second part.
  29. asparagus_cid = make_msgid()
  30. msg.add_alternative("""\
  31. <html>
  32.  <head></head>
  33.  <body>
  34.  
  35.    <img src="cid:{asparagus_cid}" />
  36.  </body>
  37. </html>
  38. """.format(asparagus_cid=asparagus_cid[1:-1]), subtype='html')
  39. # note that we needed to peel the <> off the msgid for use in the html.
  40.  
  41. # Now add the related image to the html part.
  42. with open(pic_sql, 'rb') as img:
  43.     msg.get_payload()[1].add_related(img.read(), 'dimaseg_frbulldog.jpg', 'jpeg',
  44.                                      cid=asparagus_cid)
  45. # Send the message via local SMTP server.
  46. smtpObj = smtplib.SMTP('smtp.gmail.com', 587)
  47. smtpObj.starttls()
  48. smtpObj.login('zard.41@gmail.com', 'bi31V3Iu4J')
  49. with smtpObj as s:
  50.     s.send_message(msg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement