Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#import pandas as pd
import smtplib
from email.mime.text import MIMEText
#pymongo/mongodb used for database management (users+preferences)
import pymongo
from pymongo import MongoClient
import pprint
from emails import Email
from users import User
#init the mongo client + database for users, emails, bulk mailer etc.
client = MongoClient()
db = client.bulk_mailer
users = db.users
emails = db.emails
#gather list of user preferences, emails
usersList = []
emailsList = []
for user in users.find():
usersList.append(User(user["email"], user["freebeats"], user["R&B"], user["Rap"]))
for email in emails.find():
emailsList.append(Email(email["subject"], email["body"]))
#init gmail server
server = smtplib.SMTP("smtp.gmail.com", 587)
#server = smtplib.SMTP("localhost", 1025)
server.starttls()
server.login("bulkmailer321@gmail.com", "BulkMailer321")
#loop to check for user preferences and execute
for user in usersList:
for email in emailsList:
if(user.freeBeats == "true"):
if(email.subject == "Need free beats?"):
msg = MIMEText(email.body, 'plain')
msg['Subject'] = email.subject
server.sendmail("BulkMailer321@gmail.com", user.email, msg.as_string())
server.quit()