Guest User

Untitled

a guest
May 8th, 2018
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. import smtplib
  2. from email.mime.multipart import MIMEMultipart
  3. from email.mime.text import MIMEText
  4.  
  5. SENDER_EMAIL = 'some_email@gmail.com'
  6. SENDER_PASSWORD = 'some_password'
  7. SERVER = 'smtp.gmail.com:587'
  8. RECEIVER_EMAIL = 'receiver_email@gmail.com'
  9.  
  10. SUBJECT = 'BLA-bla'
  11. HTML = """
  12. <!DOCTYPE html>
  13. <html>
  14. <head>
  15. <meta charset="utf-8" />
  16. <style type="text/css">
  17. table {
  18. background: white;
  19. border-radius:3px;
  20. border-collapse: collapse;
  21. height: auto;
  22. max-width: 900px;
  23. padding:5px;
  24. width: 100%;
  25. animation: float 5s infinite;
  26. }
  27.  
  28. th {
  29. color:#D5DDE5;;
  30. background:#1b1e24;
  31. border-bottom: 4px solid #9ea7af;
  32. font-size:14px;
  33. font-weight: 300;
  34. padding:10px;
  35. text-align:center;
  36. vertical-align:middle;
  37. }
  38.  
  39. tr {
  40. border-top: 1px solid #C1C3D1;
  41. border-bottom: 1px solid #C1C3D1;
  42. border-left: 1px solid #C1C3D1;
  43. color:#666B85;
  44. font-size:16px;
  45. font-weight:normal;
  46. }
  47.  
  48. tr:hover td {
  49. background:#4E5066;
  50. color:#FFFFFF;
  51. border-top: 1px solid #22262e;
  52. }
  53.  
  54. td {
  55. background:#FFFFFF;
  56. padding:10px;
  57. text-align:left;
  58. vertical-align:middle;
  59. font-weight:300;
  60. font-size:13px;
  61. border-right: 1px solid #C1C3D1;
  62. }
  63. </style>
  64. </head>
  65. <body>
  66. Dear Somebody,<br> <br>
  67. Bla-bla-bla<br><br>
  68.  
  69. <table>
  70. <thead>
  71. <tr style="border: 1px solid #1b1e24;">
  72. <th>head1</th>
  73. <th>head2</th>
  74. <th>head3</th>
  75. <th>head4</th>
  76. <th>head5</th>
  77. <th>head6</th>
  78. </tr>
  79. </thead>
  80. <tbody>
  81. <tr>
  82. <td>1</td>
  83. <td>2</td>
  84. <td>3</td>
  85. <td>4</td>
  86. <td>5</td>
  87. <td>6</td>
  88. </tr>
  89. <tr>
  90. <td>1</td>
  91. <td>2</td>
  92. <td>3</td>
  93. <td>4</td>
  94. <td>5</td>
  95. <td>6</td>
  96. </tr>
  97. </tbody>
  98. </table>
  99.  
  100. <br>
  101. Bla-bla.<br>
  102. For more assistance please contact our support team:
  103. <a href='mailto:some_email@gmail.com'>some_email@gmail.com</a>.<br> <br>
  104. Thank you!
  105. </body>
  106. </html>
  107. """
  108.  
  109.  
  110. def _generate_message() -> MIMEMultipart:
  111. message = MIMEMultipart("alternative", None, [MIMEText(HTML, 'html')])
  112. message['Subject'] = SUBJECT
  113. message['From'] = SENDER_EMAIL
  114. message['To'] = RECEIVER_EMAIL
  115. return message
  116.  
  117.  
  118. def send_message():
  119. message = _generate_message()
  120. server = smtplib.SMTP(SERVER)
  121. server.ehlo()
  122. server.starttls()
  123. server.login(SENDER_EMAIL, SENDER_PASSWORD)
  124. server.sendmail(SENDER_EMAIL, RECEIVER_EMAIL, message.as_string())
  125. server.quit()
  126.  
  127.  
  128. if __name__ == '__main__':
  129. send_message()
Add Comment
Please, Sign In to add comment