Skip to content

Commit

Permalink
204 gmail detects the text contents to be the same and hides them in …
Browse files Browse the repository at this point in the history
…continuous emails (#211)

* Changed the formatting to send the article names

* Use HTML to send links to the articles
  • Loading branch information
tfnribeiro authored Sep 13, 2024
1 parent 2472475 commit 0b81dc8
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions tools/send_subscription_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,28 @@
app.app_context().push()


def send_mail_new_articles_search(to_email, search):
def send_mail_new_articles_search(to_email, new_content_dict):
body = "\r\n".join(
[
"Hi there,",
" ",
"There are new articles related to your subscribed search: "
+ str(search)
+ ".",
" ",
"You can find your subscriptions here: https://www.zeeguu.org/articles/mySearches"
"There are new articles related to your subscribed " + ("searches" if len(new_content_dict) > 1 else "search") + ". You can find your subscriptions here: https://www.zeeguu.org/articles/mySearches",
" "
])

for keyword, titles in new_content_dict.items():
body += "\r\n".join([" ", f"Search: '{keyword}': "] + [f"""- <a href="{url}">{t}</a>""" for t, url in titles]) + "\n"

body += "\r\n".join([
" ",
" ",
"Cheers,",
"The Zeeguu Team",
]
)
print(f"""Sending to '{to_email}': ''{body}''""")
emailer = ZeeguuMailer("New articles to your subscribed search", body, to_email)

subject = f"New articles for {"'" + "','".join(new_content_dict.keys()) + "'"}"
emailer = ZeeguuMailer(subject, body, to_email)
emailer.send()


Expand All @@ -54,12 +58,11 @@ def send_subscription_emails():
if article.published_time > previous_day_datetime
]
if new_articles_found:
user_subscriptions[user.email] = user_subscriptions.get(user.email, []) + [
subscription.search.keywords
]
for user_email, keywords in user_subscriptions.items():
send_mail_new_articles_search(user_email, f"'{"','".join(keywords)}'")

updated_dict = user_subscriptions.get(user.email, {})
updated_dict[subscription.search.keywords] = [(article.title, article.url) for article in new_articles_found]
user_subscriptions[user.email] = updated_dict
for user_email, new_content_dict in user_subscriptions.items():
send_mail_new_articles_search(user_email, new_content_dict)

if __name__ == "__main__":
send_subscription_emails()

0 comments on commit 0b81dc8

Please sign in to comment.