brainuser5705

email sender with smtp

Sep 14th, 2021 (edited)
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import smtplib
  2. import ssl
  3.  
  4. PORT = 465
  5. SMTP_SERVER = 'smtp.gmail.com'
  6.  
  7. def smtp_send(self, email, password, receiver):
  8.     context = ssl.create_default_context()
  9.     with smtplib.SMTP_SSL(SMTP_SERVER, PORT, context=context) as server:
  10.         server.login(email, password)
  11.  
  12.         with open(receiver) as file:
  13.             reader = csv.reader(file)
  14.             for receiver_email in reader:
  15.                 server.sendmail(
  16.                     email,
  17.                     receiver_email,
  18.                     self.message.as_string()
  19.                 )
  20.  
  21.                 print('Email to', receiver_email, 'successfully sent!')
RAW Paste Data Copied