sandeep03edu

SendMailVaibhav

Dec 1st, 2022 (edited)
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.34 KB | None | 0 0
  1. import smtplib
  2. from email.mime.text import MIMEText
  3. from email.mime.multipart import MIMEMultipart
  4. from email.mime.base import MIMEBase
  5. from email import encoders
  6.  
  7. import os
  8. os.system("cls")
  9.  
  10. # Setup port number and server
  11. smtp_port = 587
  12. smtp_server = "smtp.gmail.com"
  13.  
  14. # Change this to your gmail id and set password
  15. email_from = "[email protected]"
  16. password = "setupPassword"
  17.  
  18. email_to_list = [
  19.  
  20. subject = " Invitation for Participation in Code Peak 2022 by NJACK IIT Patna and Coding Club of IIT Guwahati"
  21.  
  22. def sendMail(email_list):
  23.     for person in email_list:
  24.  
  25.         msg = MIMEMultipart()
  26.         msg['From'] = email_from
  27.         msg['To'] = person
  28.         msg['Subject'] = subject
  29.  
  30.  
  31.  
  32.         # Adding cc
  33.         cc = "[email protected]"
  34.         msg['Cc'] = cc
  35.  
  36.  
  37.  
  38.         body = '''Greetings from the community of programmers of IIT Patna and IIT Guwahati!
  39.  
  40. It gives us immense pleasure to announce that after one successful edition of Codepeak 2021, the NJACK IIT Patna and Coding Club of IIT Guwahati are organizing the 2nd edition of CODEPEAK website (Previously known as NWOC https://njackwinterofcode.github.io/).
  41.  
  42. CODE PEAK is a month-long program that helps students understand the paradigm of Open Source contribution and gives them real-world software development experience. The event targets first-timers who wish to participate in Free and Open Source(FOSS) Contributions and experienced developers who want to show their skills by contributing to real-world projects.
  43.  
  44. With this spirit, CODEPEAK is pleased to invite the students of your institute to be a part of the Competitions this year!
  45. We humbly request you share this message with your students (via the mailing lists, etc.) so that interested students do not miss out on this opportunity for growth and personal development.
  46. Please reply with a confirmation if you accept the above request!
  47.  
  48. Students' registration for CODEPEAK 22 has started.
  49.  
  50. One can check the complete timeline and details regarding Codepeak at https://www.codepeak.tech/
  51.  
  52. Best Regards
  53. Vaibhav
  54. Organizing team
  55. Code Peak 2022
  56. '''
  57.         # Adding mail body
  58.         msg.attach(MIMEText(body, 'plain'))
  59.  
  60.         # File to be sent as attachment
  61.         fileName = "Codepeak.png"
  62.  
  63.         # Opening file as binary
  64.         file = open(fileName, "rb")
  65.  
  66.         # Encoding file as Base64
  67.         attchment_package = MIMEBase("application", "octet-stream")
  68.         attchment_package.set_payload((file).read())
  69.         encoders.encode_base64(attchment_package)
  70.         attchment_package.add_header("Content-Disposition", 'attachment; filename= '+ fileName)
  71.         msg.attach(attchment_package)
  72.  
  73.         # Casting msg as string
  74.         text = msg.as_string()
  75.  
  76.         print("Sending email...")
  77.         TIE_SERVER = smtplib.SMTP(smtp_server, smtp_port)
  78.         TIE_SERVER.starttls()
  79.         TIE_SERVER.login(email_from, password)
  80.         print("Connected to server :}")
  81.  
  82.         print()
  83.         try:
  84.             print("Sending email to", person)
  85.             TIE_SERVER.sendmail(email_from, person, text)
  86.             print("Email sent successfully to", person)
  87.         except:
  88.             print("Failed to send mail to", person)
  89.         print()
  90.  
  91.     TIE_SERVER.quit()
  92.  
  93. sendMail(email_to_list)
Add Comment
Please, Sign In to add comment