diff --git a/controle_cotisation/mail_recu_headers.txt b/controle_cotisation/mail_recu_headers.txt index 11ea4d3..05a2bee 100644 --- a/controle_cotisation/mail_recu_headers.txt +++ b/controle_cotisation/mail_recu_headers.txt @@ -1,6 +1,7 @@ Content-Language: fr From: =?UTF-8?Q?Tr=c3=a9sorier_de_Libre_en_Communs?= To: +Bcc: Subject: =?UTF-8?Q?=5bTr=c3=a9sorerie=5d_Re=c3=a7u_pour_votre_cotisation_de_?= =?UTF-8?Q?membre?= Mime-Version: 1.0 diff --git a/controle_cotisation/main.py b/controle_cotisation/main.py index 20d2b43..a23d76c 100755 --- a/controle_cotisation/main.py +++ b/controle_cotisation/main.py @@ -101,11 +101,13 @@ def sendmail(headers, data): msg = bytes(headers + "\n", 'utf-8') + quopri.encodestring(bytes(data, 'utf-8')) subprocess.run([SENDMAIL_LOCATION, "-t", "-oi"], input=msg) -def sendmail_with_attachment(headers, data, attachment_header, attachment): +def sendmail_with_attachment(headers, data, attachment_header, attachment, ending): msg = bytes(headers + "\n", 'utf-8') \ + quopri.encodestring(bytes(data, 'utf-8')) \ + bytes(attachment_header + "\n", 'utf-8') \ - + bytes(attachment, 'base64') + + bytes(attachment, 'base64') \ + + bytes(ending + "\n", 'utf-8') + subprocess.run([SENDMAIL_LOCATION, "-t", "-oi"], input=msg) def gestion_get_expired(): @@ -330,6 +332,21 @@ def validate(member): os.system("cd {} && pdflatex {}".format(WORKDIR+"/validé/", filename+".tex")) os.remove(WORKDIR+"/transition/"+member) + # Preparing mail + mailheaders = get_file_content_all(RECEPT_MAIL_HEADERS) + "\n" + mailtext = get_file_content_all(RECEPT_MAIL).replace("COURRIEL-COTISANT", + answer["email"]) + "\n") + mailtattach = get_file_content_all(RECEPT_MAIL_ATTACHMENT) + "\n" + + # Opening PDF file as binary + attachment = open(WORKDIR+"/validé/", filename+".pdf", "rb") + data = attachment.read() + attachment.close() + + ending = "\n--------------3yxkFgv0AINs5nd0i6BJrWaV--" + + sendmail_with_attachment(mailheaders, mailtext, mailtattach, data, ending) + def validate_members(): for record in os.listdir(WORKDIR+"/transition"): validate(record)