From 36ad927061e89693f3245b0b6454b8743f9d9fdd Mon Sep 17 00:00:00 2001 From: leesj4 Date: Wed, 24 Nov 2021 22:06:32 +0000 Subject: [PATCH] send mail formatting --- auction/database.db | Bin 12288 -> 12288 bytes auction/routes.py | 21 ++++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/auction/database.db b/auction/database.db index aded12bb1337da153b42a0f2f2a2331c92d53a2c..a4e7ae78e9afe89c614c3f82d3d98b7cda5d9c57 100644 GIT binary patch delta 155 zcmZojXh@hK&8R$4#+gxhW5PmtX`ZPJT-+H9{7d*Xxik18c>i!;LM9dl mOrERD&B(cVrLH6+Zz?kngJduhRB@@c&g8|~dXqKvuLA%Ib|k6* diff --git a/auction/routes.py b/auction/routes.py index 6290396..cd96de6 100644 --- a/auction/routes.py +++ b/auction/routes.py @@ -191,7 +191,7 @@ def sold(item_id): # allows a user to mark an item as sold # prevents another user marking items they don't own if item.user_id == user.id: # if the current user is the items owner - item.sold = True + item.sold = False db.session.commit() else: @@ -228,21 +228,24 @@ def bid(item_id): # allows a user to bid on an item def notify_winner(winner, item): # emails a user if they win an auction - message = "you have won the "+item.item_name+" auction!!" # not allowing me to send an email with a link in it, coming in blank - winner_email = winner.email - send_email("pythonflaskemail@gmail.com", "josephlees79@gmail.com", message) # changed reciever to reduce spam when testing + subj = "You won an auction!" + body = "Hey {}!".format(winner.username) + body += "\nYou just won the {} auction!".format(item.item_name) # not allowing me to send an email with a link in it, coming in blank + send_email("pythonflaskemail@gmail.com", winner.email, subj, body) # changed reciever to reduce spam when testing def notify_outbid(user, item): # emails a user if they are outbid - message = "you have been outbid on the "+item.item_name+" auction!" # wont allow me to put a link in the email - outbid_email = user.email - send_email("pythonflaskemail@gmail.com", "josephlees79@gmail.com", message) + subj = "You were just outbid!" + body = "Hey {}!".format(user.username) + body += "\nYou just got outbid on the {} auction!".format(item.item_name) # wont allow me to put a link in the email + send_email("pythonflaskemail@gmail.com", user.email, subj, body) -def send_email(sender, reciever, message): # sends the email using smtplib module +def send_email(sender, reciever, subj, message): # sends the email using smtplib module password = "Python150*" + msg = "From: %s\nTo: %s\nSubject: %s\n\n%s" % ( sender, reciever, subj, message ) server = smtplib.SMTP("smtp.gmail.com", 587) server.starttls() server.login(sender, password) - server.sendmail(sender, "josephlees79@gmail.com", message) \ No newline at end of file + server.sendmail(sender, "josephlees79@gmail.com", msg) \ No newline at end of file