-
Notifications
You must be signed in to change notification settings - Fork 8
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
4 changed files
with
62 additions
and
98 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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 2.2.13 on 2024-11-25 20:35 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('application', '0026_auto_20241119_1945'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='application', | ||
name='wants_team', | ||
field=models.CharField(choices=[('Friend', 'From a friend'), ('Tabling', 'Tabling outside Zachry'), ('Howdy Week', 'From Howdy Week'), ('Yard Sign', 'Yard sign'), ('Social Media', 'Social media'), ('Student Orgs', 'Though another student org'), ('TH Organizer', 'From a TAMUhack organizer'), ('ENGR Newsletter', 'From the TAMU Engineering Newsletter'), ('MLH', 'Major League Hacking (MLH)'), ('Attended Before', "I've attended TAMUhack before")], max_length=16, verbose_name='How did you hear about TAMUhack?'), | ||
), | ||
] |
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,46 +1,27 @@ | ||
from django.core.mail import get_connection, EmailMultiAlternatives | ||
import threading | ||
|
||
#create separate Threading class for mass emails | ||
class MassEmailThread(threading.Thread): | ||
def __init__(self, subject, text_content, html_content, from_email, recipient_list, connection): | ||
threading.Thread.__init__(self) | ||
self.subject = subject | ||
self.text_content = text_content | ||
self.html_content = html_content | ||
self.from_email = from_email | ||
self.recipient_list = recipient_list | ||
self.connection = connection | ||
self.result = 0 | ||
|
||
def run(self): | ||
email = EmailMultiAlternatives(self.subject, self.text_content, self.from_email, self.recipient_list) | ||
email.attach_alternative(self.html_content, "text/html") | ||
try: | ||
self.result = email.send(fail_silently=False, connection=self.connection) | ||
except Exception as e: | ||
print("Error sending email: ", e) | ||
self.result = 0 | ||
|
||
def send_mass_html_mail(datatuple, fail_silently=False, user=None, password=None, connection=None): | ||
def send_mass_html_mail( | ||
datatuple, fail_silently=False, user=None, password=None, connection=None | ||
): | ||
""" | ||
Sends each message in datatuple (subject, text_content, html_content, from_email, recipient_list). | ||
Returns the number of emails sent. | ||
Given a datatuple of (subject, text_content, html_content, from_email, | ||
recipient_list), sends each message to each recipient list. Returns the | ||
number of emails sent. | ||
If from_email is None, the DEFAULT_FROM_EMAIL setting is used. | ||
If auth_user and auth_password are set, they're used to log in. | ||
If auth_user is None, the EMAIL_HOST_USER setting is used. | ||
If auth_password is None, the EMAIL_HOST_PASSWORD setting is used. | ||
(from <a href="https://stackoverflow.com/a/10215091">this StackOverflow answer</a> | ||
""" | ||
connection = connection or get_connection( | ||
username=user, password=password, fail_silently=fail_silently | ||
) | ||
|
||
threads = [] | ||
|
||
messages = [] | ||
for subject, text, html, from_email, recipient in datatuple: | ||
email_thread = MassEmailThread(subject, text, html, from_email, recipient, connection) | ||
email_thread.start() | ||
threads.append(email_thread) | ||
|
||
for thread in threads: | ||
thread.join() | ||
|
||
total_sent = sum(thread.result for thread in threads if thread.result) | ||
|
||
return total_sent | ||
message = EmailMultiAlternatives(subject, text, from_email, recipient) | ||
message.attach_alternative(html, "text/html") | ||
messages.append(message) | ||
return connection.send_messages(messages) |
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