load-net

Отправить почту python

Mar 3rd, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. #DEBIAN
  2. #python3 -m venv /usr/src/skri/
  3. #mcedit /usr/src/skri/skri.py
  4. #source /usr/src/skri/bin/activate
  5. #pip install requests
  6. #cd /usr/src/skri/
  7. #python3 /usr/src/skri/skri.py
  8.  
  9. #Windows
  10. #python -m venv D:\projects\pochta
  11. #cd D:\projects\pochta
  12. #D:\projects\pochta\Scripts\activate
  13. #pip install requests
  14. #python skri.py
  15.  
  16.  
  17.  
  18.  
  19. from base64 import b64decode
  20. import requests
  21. import smtplib
  22. from os.path import basename
  23. from email.mime.application import MIMEApplication
  24. from email.mime.multipart import MIMEMultipart
  25. from email.mime.text import MIMEText
  26. from email.utils import COMMASPACE, formatdate
  27. import re
  28.  
  29. def send_mail(files=None, notification=""):
  30. sender_address = '[email protected]'
  31. sender_pass = 'takxkccccccccc'
  32. receiver_address = ["[email protected]", "[email protected]"]
  33. mail_content = notification + "\n" + '''See attachements
  34. &
  35. &&/ ##(&%
  36. #((&&&/((&&
  37. &/(#&&/((((&(
  38. &///&//((((#&&%
  39. &//((((((((((((&(/&
  40. &/(/%(((((((((((((&((/&
  41. &//(/&&. &(((((((((((((((/&/
  42. &//((/& &((((((&&%(((&#&&&
  43. &//(((/& &((((((&(((((((&&&(///&
  44. &//((((((((((((((((((&&((((((((((&&&&&&
  45. ,%//(((((((((((((((((((((&/(((((((((&#((&%
  46. &//(((((((((((((((((((&&&&&&/((((((((&((%@
  47. &/(%&&(((((((((((((((&& &/((((((&(
  48. &/((&(((((((((((((((&& &&((((((((&&
  49. &(((((((((((((&&&&&& &///(((((&&
  50. &((((((((((&&&&& &&/(((((&&
  51. &&#((((&&& &//((((&&&
  52. &&&/(((((&&
  53. &&&&/
  54. '''
  55. msg = MIMEMultipart()
  56. msg['From'] = sender_address
  57. msg['To'] = ", ".join(receiver_address)
  58. msg['Date'] = formatdate(localtime=True)
  59. msg['Subject'] = 'Notification from server'
  60.  
  61. msg.attach(MIMEText(mail_content, 'plain'))
  62.  
  63. for f in files or []:
  64. with open(f, "rb") as fil:
  65. part = MIMEApplication(
  66. fil.read(),
  67. Name=basename(f)
  68. )
  69. # After the file is closed
  70. part['Content-Disposition'] = 'attachment; filename="%s"' % basename(f)
  71. msg.attach(part)
  72.  
  73.  
  74. session = smtplib.SMTP('smtp.yandex.ru', 587)
  75. session.starttls() #enable security
  76. session.login(sender_address, sender_pass) #login with mail_id and password
  77. text = msg.as_string()
  78. session.sendmail(sender_address, receiver_address, text)
  79. session.quit()
  80. print('Mail Sent')
  81.  
  82.  
  83. send_mail(["D:/projects/pochta/skri.py"], "Privet")
Add Comment
Please, Sign In to add comment