diff --git a/setup.cfg b/setup.cfg index 5f900e8a7c835130663c629b95bd0e105742df2b..40b6bcee056fbe223ab4876678c84c333b44c442 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,6 +31,12 @@ setup_requires = where = src include = stapa.* +[options.package_data] +stapa.mailsync.resources = + *.html + *.txt + *.pdf + [options.entry_points] console_scripts = sync_stapa_all=stapa.mailsync.cli:sync diff --git a/src/stapa/mailsync/cli.py b/src/stapa/mailsync/cli.py index 56a9575e8b6f85e26e80bbb59bdb9da0b2283041..3142824b5c8673039bdb44ad7d0275969100f248 100644 --- a/src/stapa/mailsync/cli.py +++ b/src/stapa/mailsync/cli.py @@ -11,6 +11,7 @@ from zolfa.zauth.pasteur import PasteurEmail from .join_request_checker import fetch_join_requests from .mailinglist import MailingListManager from .utils import ask_confirm +from .welcome_mail import WelcomeMailSender data_dir = Path(xdgappdirs.user_data_dir("stapa_mailsync")) members_backup_dir = data_dir / "backup_members" @@ -79,7 +80,7 @@ def sync(): return if not ask_confirm(): return - + add_results = ml.bulk_add(set(to_add['address'])) ts = datetime.utcnow().isoformat(timespec='seconds') log_entry = {ts: add_results} @@ -96,13 +97,21 @@ def sync(): print('\nResults:\n') print(check_results.to_markdown()) - print('\nPlease send welcome mail to:') - print("; ".join(check_results[check_results.state == 'ADDED'].address)) + added_addresses = check_results[check_results.state == 'ADDED'].address + added_addresses = added_addresses.to_list() + print('\nSending welcome mail to:') + print("; ".join(added_addresses)) print("") ts = datetime.utcnow().isoformat(timespec='seconds') members = ml.members() members.to_csv(members_backup_dir / f'{ts}.csv') + wms = WelcomeMailSender(args.username, password) + wms.send_mails(added_addresses) + + print("Welcome emails sent!") + + if __name__ == '__main__': sync() diff --git a/src/stapa/mailsync/resources/StaPaMailingList.pdf b/src/stapa/mailsync/resources/StaPaMailingList.pdf new file mode 100644 index 0000000000000000000000000000000000000000..97ac2631ae7bbc8de46f514d965694eaeff692b3 Binary files /dev/null and b/src/stapa/mailsync/resources/StaPaMailingList.pdf differ diff --git a/src/stapa/mailsync/resources/welcome_mail.html b/src/stapa/mailsync/resources/welcome_mail.html new file mode 100644 index 0000000000000000000000000000000000000000..55c569d6ce307991a5247755d366eae82df5ddde --- /dev/null +++ b/src/stapa/mailsync/resources/welcome_mail.html @@ -0,0 +1,134 @@ +<!DOCTYPE html> +<html> + <head> + <meta http-equiv="content-type" content="text/html; charset="> + </head> + <body dir="ltr"> + <font size="5">🎉</font> <font style="font-size:18pt" size="5"> <b>Welcome to the StaPa mailing list!</b> </font> + <font style="font-size:18pt" size="5">🎉</font> + <div id="divtagdefaultwrapper" dir="ltr" style="font-size:12pt;font-family:Arial,serif"> + <div> + <p style="line-height:100%; margin-top:0.49cm; margin-bottom:0.49cm"> You are receiving this email because you + asked to be added to the StaPa mailing list through our website: <font color="#0070c0"> <a + href="http://stapa.ovh/"><u>http://stapa.ovh</u></a> </font> and your request has now been successfully + processed! </p> + <p style="line-height:100%; margin-bottom:0.11cm"> Starting from now, you will be receiving in your inbox all + the messages that are exchanged on our list! </p> + <p style="line-height:100%; margin-bottom:0.11cm"> You are also welcome to participate and send emails directly + to the list, by sending your email to the address <a href="mailto:stapa-all@pasteur.fr"><font color="#0070c0">stapa-all@pasteur.fr</font></a> + <font color="#d05c12"><b> but please, take some time to read the following lines before doing so: </b></font> + </p> + <ul> + <li> + <p style="line-height:100%; margin-top:0.42cm; margin-bottom:0.42cm"> This is an open (unmoderated - for the + moment) mailing list. When you send an email to 'stapa-all@pasteur.fr' all the hundreds of subscribers + will receive your email, so use it wisely! For example: <b> if someone asks for help on the mailing list, + and you want to reply to that particular person <font color="#d05c12"> pretty pretty please + double-check that you are not choosing the 'Reply to all' option! </font> </b> If you select 'Reply + to all' you will send your answer to all the subscribers! </p> + </li> + <li> + <p style="line-height:100%; margin-top:0.42cm; margin-bottom:0.42cm"> (At the moment) there is no defined + list of "allowed" topics, but common-sense rules still apply. You are welcome to send messages, requests + or useful information, but to keep this place useful and enjoyable, please, let's try to avoid + counterproductive messages and think twice before sending! </p> + </li> + <li> + <p style="line-height:100%; margin-top:0.42cm; margin-bottom:0.42cm"> <font style="font-size:16pt" size="3"> + <b>Our priority is to keep this space a safe place for everyone,</b> </font> so we won't tolerate: any + form of hate speech or discrimination, any aggressive or abusive behavior, any kind of propaganda linked + to political parties. </p> + </li> + </ul> + <p style="line-height:100%; margin-top:0.53cm; margin-bottom:0.11cm"> Here you can find a (non-exhaustive) list + of topics that have always been well-received by the members of the mailing list: </p> + <ul> + <li> + <p style="line-height:100%; margin-top:0.49cm; margin-bottom:0cm"> <u>Science-related topics</u>, i.e.: </p> + </li> + <ul> + <li> + <p style="line-height:100%; margin-bottom:0cm"> Kindly ask your colleagues on campus if they can supply + small quantities of a reagent for an experiment you have to do (one of the main uses of the mailing list + until now) </p> + </li> + <li> + <p style="line-height:100%; margin-bottom:0cm"> Ask if someone on campus can give expertise/quick + suggestions on a topic you are working on (but, please, make sure to ask in your lab first, to avoid any + trouble! 😉) </p> + </li> + </ul> + <li> + <p style="line-height:100%; margin-bottom:0cm"> <u>Campus social life:</u> </p> + </li> + <ul> + <li> + <p style="line-height:100%; margin-bottom:0cm"> Cool events (scientific or not) happening on campus that + can be of general interest. </p> + </li> + <li> + <p style="line-height:100%; margin-bottom:0cm"> Activities organized by on-campus organizations </p> + </li> + <li> + <p style="line-height:100%; margin-bottom:0cm"> Proposals or discussion on topics that could be of general + interest. </p> + </li> + </ul> + <li> + <p style="line-height:100%; margin-bottom:0cm"> <u>Networking / job proposals / applications</u> </p> + </li> + <ul> + <li> + <p style="line-height:100%; margin-bottom:0cm"> Open positions </p> + </li> + <li> + <p style="line-height:100%; margin-bottom:0cm">Conferences</p> + </li> + <li> + <p style="line-height:100%; margin-bottom:0cm">...</p> + </li> + </ul> + <li> + <p style="line-height:100%; margin-bottom:0cm"> <u>Anything that could be of general interest</u> </p> + </li> + </ul> + <p style="line-height:100%; margin-top:0.99cm; margin-bottom:0.99cm"> Sometimes receiving all the StaPa emails + in your main inbox can be overwhelming. You may prefer to have them moved automatically in a dedicated folder. + To help you in this endeavor, please find attached a PDF guide and configure your Outlook accordingly, if you + wish to do so. <font color="#d05c12"> (However, don't forget to check that folder once in a while not to miss + out on the cool events we organize, like the weekly StaPa Social Time, every Friday at 18h00 in the 25). </font> + </p> + <p style="line-height:100%; margin-top:0.99cm; margin-bottom:0.99cm"> If you come across any specific issue or + problem that you want to bring to the attention of the StaPa Bureau, please don't refrain from contacting us + at <font color="#0000ff"> <u><a href="mailto:bureau-stapa@pasteur.fr" class="moz-txt-link-freetext"> + bureau-stapa@pasteur.fr </a></u> </font>. </p> + <p style="line-height:100%; margin-bottom:0cm"> Thank you for joining the StaPa mailing list! </p> + <p style="line-height:100%; margin-bottom:1cm"> We hope to see you soon in one of our events 😁 </p> + <p style="line-height:100%; margin-bottom:0cm"> Cheers, </p> + <p style="line-height:100%; margin-bottom:2cm"> The StaPa Bureau </p> + <p style="line-height:100%; margin-bottom:0cm"> <u>Unsubscribe:</u> If at any time you want to quit the mailing + list and stop receiving the messages, you can do it yourself following these instructions (no need to ask): </p> + <ul> + <li> + <p style="line-height:100%; margin-bottom:0cm"> Access the Pasteur Webmail in your browser (<u><a + href="https://email.pasteur.fr/" class="moz-txt-link-freetext">https://email.pasteur.fr</a></u>) </p> + </li> + <li> + <p style="line-height:100%; margin-bottom:0cm"> Click on the gear icon on the top-right corner, then select + Settings (FR: Options) </p> + </li> + <li> + <p style="line-height:100%; margin-bottom:0cm"> In the menu in the left pane find the section General -> + Distribution Groups (FR: Groupes de Distribution) </p> + </li> + <li> + <p style="line-height:100%; margin-bottom:0cm"> Double click on stapa-all </p> + </li> + <li> + <p style="line-height:100%; margin-bottom:0cm">Click on Leave (FR: Quitter)</p> + </li> + </ul> + </div> + </div> + </body> +</html> diff --git a/src/stapa/mailsync/resources/welcome_mail.txt b/src/stapa/mailsync/resources/welcome_mail.txt new file mode 100644 index 0000000000000000000000000000000000000000..5cc7a1304834689cbc5a3da95aa265f5569d1188 --- /dev/null +++ b/src/stapa/mailsync/resources/welcome_mail.txt @@ -0,0 +1,100 @@ + *Welcome to the StaPa mailing list!* + +You are receiving this email because you asked to be added to the StaPa +mailing list through our website: http://stapa.ovh/, and your request has +now been successfully processed! + +Starting from now, you will be receiving in your inbox all the messages +that are exchanged on our list! + +You are also welcome to participate and send emails directly to the +list, by sending your email to the address stapa-all@pasteur.fr +*but please, take some time to read the following lines before doing so*: + + - This is an open (unmoderated - for the moment) mailing list. When + you send an email to 'stapa-all@pasteur.fr' all the hundreds of + subscribers will receive your email, so use it wisely! For example: + *if someone asks for help on the mailing list, and you want to reply + to that particular person pretty pretty please double-check that you + are not choosing the 'Reply to all' option!* If you select 'Reply + to all' you will send your answer to all the subscribers! + + - (At the moment) there is no defined list of "allowed" topics, but + common-sense rules still apply. You are welcome to send messages, + requests or useful information, but to keep this place useful and + enjoyable, please, let's try to avoid counterproductive messages and + think twice before sending! + + - *Our priority is to keep this space a safe place for everyone,* so + we won't tolerate: any form of hate speech or discrimination, any + aggressive or abusive behavior, any kind of propaganda linked to + political parties. + +Here you can find a (non-exhaustive) list of topics that have always=20 +been well-received by the members of the mailing list: + + - _Science-related topics_, i.e.: + + + Kindly ask your colleagues on campus if they can supply small + quantities of a reagent for an experiment you have to do (one of + the main uses of the mailing list until now) + + + Ask if someone on campus can give expertise/quick suggestions on + a topic you are working on (but, please, make sure to ask in + your lab first, to avoid any trouble! =F0=9F=98=89) + + - _Campus social life:_ + + + Cool events (scientific or not) happening on campus that can be + of general interest. + + + Activities organized by on-campus organizations + + + Proposals or discussion on topics that could be of general + interest. + + - _Networking / job proposals / applications_ + + + Open positions + + + Conferences + + + ... + + - _Anything that could be of general interest_ + +Sometimes receiving all the StaPa emails in your main inbox can be +overwhelming. You may prefer to have them moved automatically in a +dedicated folder. To help you in this endeavor, please find attached a +PDF guide and configure your Outlook accordingly, if you wish to do so. +(However, don't forget to check that folder once in a while not to miss +out on the cool events we organize, like the weekly StaPa Social Time, +every Friday at 18h00 in the 25). + +If you come across any specific issue or problem that you want to bring +to the attention of the StaPa Bureau, please don't refrain from +contacting us at: bureau-stapa@pasteur.fr + +Thank you for joining the StaPa mailing list! + +We hope to see you soon in one of our events :) + +Cheers, + +The StaPa Bureau + +_Unsubscribe:_ If at any time you want to quit the mailing list and stop=20 +receiving the messages, you can do it yourself following these=20 +instructions (no need to ask): + + - Access the Pasteur Webmail in your browser (https://email.pasteur.fr) + + - Click on the gear icon on the top-right corner, then select Settings + (FR: Options) + + - In the menu in the left pane find the section General -> + Distribution Groups (FR: Groupes de Distribution) + + - Double click on stapa-all + + - Click on Leave (FR: Quitter) diff --git a/src/stapa/mailsync/welcome_mail.py b/src/stapa/mailsync/welcome_mail.py new file mode 100644 index 0000000000000000000000000000000000000000..9055b0be035bcc14846a967dee2b15290ea496ea --- /dev/null +++ b/src/stapa/mailsync/welcome_mail.py @@ -0,0 +1,53 @@ +import pkgutil +from smtplib import SMTP +from email.mime.multipart import MIMEMultipart +from email.mime.base import MIMEBase +from email.mime.text import MIMEText +from email.mime.application import MIMEApplication +from time import sleep +from tqdm.auto import tqdm + + +def get_resource(name): + return pkgutil.get_data(__package__, 'resources/' + name) + + +class WelcomeMailSender: + def __init__(self, username, password): + self.username = username + self.password = password + + text = get_resource('welcome_mail.txt').decode('utf-8') + html = get_resource('welcome_mail.html').decode('utf-8') + + text_part = MIMEText(text, 'plain') + html_part = MIMEText(html, 'html') + + self._msg_alternative = MIMEMultipart('alternative') + self._msg_alternative.attach(text_part) + self._msg_alternative.attach(html_part) + + filename = 'StaPaMailingList.pdf' + attachment = get_resource(filename) + self._msg_attachment = MIMEApplication(attachment, _subtype="pdf") + self._msg_attachment.add_header('Content-Disposition', 'attachment', + filename=filename) + + def prepare_msg(self, to): + msg_mixed = MIMEMultipart('mixed') + msg_mixed.attach(self._msg_alternative) + msg_mixed.attach(self._msg_attachment) + msg_mixed['From'] = 'StaPa <stapa@pasteur.fr>' + msg_mixed['To'] = to + msg_mixed['Subject'] = '🎉 Welcome to the StaPa mailing list!' + return msg_mixed + + def send_mails(self, emails): + s = SMTP(host='email.pasteur.fr', port=587) + s.starttls() + s.login(self.username + "@pasteur.fr", self.password) + + for email in tqdm(emails): + msg = self.prepare_msg(email) + s.sendmail(msg['From'], msg['To'], msg.as_string()) + sleep(1)