Advertisement
przedmarancza

send_email.py

Mar 5th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. import smtplib
  2. import db_init
  3.  
  4.  
  5. def create_msg():
  6.     if db_init.find_new() != []:
  7.         i = 0
  8.         msgtext = 'Hello, \n\n'
  9.  
  10.         for newrecord in db_init.find_new():
  11.             i+=1
  12.             msgtext += "{}. Title: {}\nDate: {}\nSalary: " \
  13.                            "{}\nAdvertisement: {}...\nLink: {}\n\n\n".format(i, newrecord[1], newrecord[2],
  14.                                                                                 newrecord[3],newrecord[4][0:60],
  15.                                                                                 newrecord[5])
  16.         return send_email(msgtext)
  17.  
  18.  
  19. def send_email(fullMsg):
  20.     subject = "New job offers"
  21.  
  22.     message = 'Subject: {}\n\n{}'.format(subject, fullMsg).encode('utf-8')
  23.  
  24.     mail = smtplib.SMTP('smtp.gmail.com', 587)
  25.  
  26.     mail.ehlo()
  27.     mail.starttls()
  28.  
  29.     mail.login(user='::login::@gmail.com', password='::password::')  # email and password to account
  30.  
  31.     mail.sendmail('::login:@gmail.com', '::login::@gmail.com',
  32.                   message)
  33.  
  34.     mail.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement