This repository has been archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
30 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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() | ||
|
@@ -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 not shown.