Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
make final tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Elias2660 committed Jun 1, 2024
1 parent 7b1be73 commit 4e6e3a3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
19 changes: 13 additions & 6 deletions Main/Main.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@

# %%
import pandas as pd
import numpy as np
from SendEmail import send_email
import time

data = pd.read_csv('../data/actualfinaljpromlist.csv', names = ["date", "sessionid", "ip", "name", "number1", "1staddress", "place", "state", "number2", "number3", "paid", "blank","blank2", "approval", "email", "name2", "email2", "osis", "homeroom", "purchase"])

# %%

start = 0
end = 100
start = 100
end = 220

# %%

highest = data.shape[0]

# %%

for i in range(start, end):
for i in range(start, min(end, highest)):
p = data.iloc[i]
name = (str(p["name2"]).strip().split(" ")[0]).strip()
name = name[0].upper() + name[1:]
email = p["email"].strip()
session_id = p["sessionid"].strip()
approval = p["approval"]
if ("Approved" in approval) :
send_email([email, "[email protected]", "[email protected]", "[email protected]"], session_id, name)

print(send_email([email, "[email protected]", "[email protected]", "[email protected]"], session_id, name))
time.sleep(3)
else:
print(f"{name} is not approved")



27 changes: 17 additions & 10 deletions Main/SendEmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def send_email(recipients: list, session: str, name: str) -> str:
if not SMTPserver or not sender or not USERNAME or not PASSWORD:
sys.exit("Missing environment variables")

print(f"SMTP Server: {SMTPserver}")
print(f"Sender: {sender}")
print(f"Username: {USERNAME}")
# print(f"SMTP Server: {SMTPserver}")
# print(f"Sender: {sender}")
# print(f"Username: {USERNAME}")

content = f"""
<html>
Expand All @@ -44,7 +44,7 @@ def send_email(recipients: list, session: str, name: str) -> str:
</body>
</html>"""

subject = "Your Jprom Ticket"
subject = "Your Junior Prom 2024 Ticket"

try:
msg = EmailMessage()
Expand All @@ -58,22 +58,29 @@ def send_email(recipients: list, session: str, name: str) -> str:

msg.set_content(content, subtype="html")
CreateBarcode.createBarcode(session, "barcode_image.png")
attachFile.attach_file(msg, "barcode_image.png")

try:
attachFile.attach_file(msg, "barcode_image.png")
except Exception as e:
print(f"Failed to attach file to {name}: {str(e)}")
return


conn = SMTP(SMTPserver)
conn.set_debuglevel(True) # Enable debugging output
# conn.set_debuglevel(True) # Enable debugging output
conn.login(USERNAME, PASSWORD)
try:
conn.sendmail(sender, recipients, msg.as_string())
finally:
conn.quit()
return "Mail sent successfully"
return f"Mail sent successfully to {name}"

except Exception as e:
print("Mail failed:", str(e))
sys.exit(f"Mail failed; {str(e)}")
return
# sys.exit(f"Mail failed; {str(e)}")


if __name__ == "__main__":
# print(send_email(["esie50@stuy.edu"], 2083480230980, "Ethan"))
print(send_email(["exu51@stuy.edu"], 2083480230980, "Ethan"))
# print(send_email(["[email protected]"], 2083480230980, "Will"))
print()
Binary file modified Main/__pycache__/SendEmail.cpython-39.pyc
Binary file not shown.

0 comments on commit 4e6e3a3

Please sign in to comment.