Guest User

Untitled

a guest
Feb 25th, 2018
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import pandas as pd
  2. import csv
  3. from tabulate import tabulate
  4. from email.mime.multipart import MIMEMultipart
  5. from email.mime.text import MIMEText
  6. import smtplib
  7.  
  8. me = 'myemailaddress@gmail.com'
  9. password = 'password'
  10. server = 'smtp.gmail.com:587'
  11. you = 'myemailaddress@gmail.com'
  12.  
  13. text = """
  14. Hello, Friend.
  15.  
  16. Here is your data:
  17.  
  18. {table}
  19.  
  20. Regards,
  21.  
  22. Me"""
  23.  
  24. html = """
  25. <html>
  26. <head>
  27. <style>
  28. table, th, td {{ border: 1px solid black; border-collapse: collapse; }}
  29. th, td {{ padding: 5px; }}
  30. </style>
  31. </head>
  32. <body><p>Hello, Friend This data is from a data frame.</p>
  33. <p>Here is your data:</p>
  34. {table}
  35. <p>Regards,</p>
  36. <p>Me</p>
  37. </body></html>
  38. """
  39.  
  40. # with open('input.csv') as input_file:
  41. # reader = csv.reader(input_file)
  42. # data = list(reader)
  43.  
  44. data = pd.read_csv("MySampleFile.csv")
  45. text = text.format(table=tabulate(data, headers="firstrow", tablefmt="grid"))
  46. html = html.format(table=tabulate(data, headers="firstrow", tablefmt="html"))
  47.  
  48. message = MIMEMultipart(
  49. "alternative", None, [MIMEText(text), MIMEText(html,'html')])
  50.  
  51. message['Subject'] = "First Attempt"
  52. message['From'] = me
  53. message['To'] = you
  54. server = smtplib.SMTP(server)
  55. server.ehlo()
  56. server.starttls()
  57. server.login(me, password)
  58. server.sendmail(me, you, message.as_string())
  59. server.quit()
Add Comment
Please, Sign In to add comment