Reputation: 67
I have a Django management command defined like this:
class Command(BaseCommand):
help = "Sends out an email with new jobs added in a timespan of a week"
def handle(self, *args, **options):
time_a_week_ago = timezone.now() - timedelta(days=7)
time_now = timezone.now()
job_listings_added_this_week = JobListing.objects.filter(time_added__gte=time_a_week_ago, time_added__lt=time_now)
email_subscribers = EmailSubscriber.objects.all()
emails = []
for subscriber in email_subscribers:
emails.append(subscriber.email)
msg_plain = render_to_string("employers/weekly_newsletter.txt", {"joblistings_list": job_listings_added_this_week})
msg_html = render_to_string("employers/weekly_newsletter.html", {"joblistings_list": job_listings_added_this_week})
msg = EmailMultiAlternatives("New jobs added this week", msg_plain, "[email protected]", [], bcc=[emails])
msg.attach_alternative(msg_html, "text/html")
msg.send()
self.stdout.write(self.style.SUCCESS("Successfuly sent out the weekly email."))
I set the email content to be output to a file. When I run the management command, this is is what I get:
Content-Type: multipart/alternative;
boundary="===============8145459042862347861=="
MIME-Version: 1.0
Subject: New jobs added this week
From: [email protected]
Date: Thu, 12 Nov 2020 05:23:05 -0000
Message-ID:
<[email protected]>
--===============8145459042862347861==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Jobs added last week
Hey! These job listings were added last week:
Test job 5 - click here: http://127.0.0.1:8000/12/
Test job 6 - click here: http://127.0.0.1:8000/13/
--===============8145459042862347861==
Content-Type: text/html; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
<h1> Jobs added last week </h1>
<p> Hey! These job listings were added last week: </p>
<ul>
<li><a href="http://127.0.0.1:8000/12/">Test job 5</a></li>
<li><a href="http://127.0.0.1:8000/13/">Test job 6</a></li>
</ul>
--===============8145459042862347861==--
-------------------------------------------------------------------------------
In the email header, I see no Bcc. Why is that? Why is my EmailMultiAlternatives not including the Bcc header?
Upvotes: 0
Views: 259
Reputation: 409
Try Changing bcc=[emails]
to bcc=emails
Since emails
is already a list, you won't need additional square brackets
Upvotes: 0