Compare commits
No commits in common. "3589ab01cd922f2358e7b136f86fd9bc6554891e" and "69dd40b2a28ed7008a887f592f5947a4c73c9f8b" have entirely different histories.
3589ab01cd
...
69dd40b2a2
|
@ -2,4 +2,5 @@ From: =?UTF-8?Q?Secr=c3=a9taire_de_Libre_en_Communs?= <secretaire@a-lec.org>
|
||||||
To: <COURRIEL_INSCRIPTION>
|
To: <COURRIEL_INSCRIPTION>
|
||||||
Bcc: <secretaire@a-lec.org>, <tresorier@a-lec.org>
|
Bcc: <secretaire@a-lec.org>, <tresorier@a-lec.org>
|
||||||
Subject: =?UTF-8?Q?=5bSecr=c3=a9tariat=5d_Confirmation de votre adh=c3=a9sion?=
|
Subject: =?UTF-8?Q?=5bSecr=c3=a9tariat=5d_Confirmation de votre adh=c3=a9sion?=
|
||||||
Content-Transfer-Encoding: quoted-printable
|
Content-Type: text/plain; charset="UTF-8"
|
||||||
|
Content-Transfer-Encoding: quoted-printable
|
|
@ -3,4 +3,5 @@ From: =?UTF-8?Q?Tr=c3=a9sorier_de_Libre_en_Communs?= <tresorier@a-lec.org>
|
||||||
To: <COURRIEL-COTISANT>
|
To: <COURRIEL-COTISANT>
|
||||||
Bcc: <tresorier@a-lec.org>
|
Bcc: <tresorier@a-lec.org>
|
||||||
Subject: =?UTF-8?Q?Modalit=c3=a9s_de_r=c3=a8glement_de_votre_cotisation_ANNEE_CIVILE?=
|
Subject: =?UTF-8?Q?Modalit=c3=a9s_de_r=c3=a8glement_de_votre_cotisation_ANNEE_CIVILE?=
|
||||||
|
Content-Type: text/plain; charset="UTF-8"
|
||||||
Content-Transfer-Encoding: quoted-printable
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
|
@ -2,4 +2,5 @@ From: tresorier@a-lec.org
|
||||||
To: tresorier@a-lec.org
|
To: tresorier@a-lec.org
|
||||||
Subject: Suivi automatique des cotisations
|
Subject: Suivi automatique des cotisations
|
||||||
MIME-Version: 1.0
|
MIME-Version: 1.0
|
||||||
Content-Transfer-Encoding: quoted-printable
|
Content-Type: text/plain; charset="UTF-8"
|
||||||
|
Content-Transfer-Encoding: quoted-printable
|
|
@ -8,4 +8,5 @@ Content-Type: multipart/mixed; boundary="------------3yxkFgv0AINs5nd0i6BJrWaV"
|
||||||
|
|
||||||
This is a multi-part message in MIME format.
|
This is a multi-part message in MIME format.
|
||||||
--------------3yxkFgv0AINs5nd0i6BJrWaV
|
--------------3yxkFgv0AINs5nd0i6BJrWaV
|
||||||
|
Content-Type: text/plain; charset="UTF-8"
|
||||||
Content-Transfer-Encoding: quoted-printable
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
|
@ -115,10 +115,8 @@ def setup_workdir():
|
||||||
|
|
||||||
|
|
||||||
def sendmail_with_attachment(headers, data, attachment_path=None, filename=None):
|
def sendmail_with_attachment(headers, data, attachment_path=None, filename=None):
|
||||||
# Create a multipart message
|
# Parse headers
|
||||||
msg = MIMEMultipart()
|
msg = MIMEMultipart()
|
||||||
|
|
||||||
# Add the headers without manually setting Content-Type or MIME-Version
|
|
||||||
for header in headers.split("\n"):
|
for header in headers.split("\n"):
|
||||||
if ": " in header:
|
if ": " in header:
|
||||||
key, value = header.split(": ", 1)
|
key, value = header.split(": ", 1)
|
||||||
|
@ -130,8 +128,8 @@ def sendmail_with_attachment(headers, data, attachment_path=None, filename=None)
|
||||||
|
|
||||||
# Add the attachment only if attachment_path is provided
|
# Add the attachment only if attachment_path is provided
|
||||||
if attachment_path and filename:
|
if attachment_path and filename:
|
||||||
|
attachment = MIMEBase('application', 'octet-stream')
|
||||||
with open(attachment_path, "rb") as attach_file:
|
with open(attachment_path, "rb") as attach_file:
|
||||||
attachment = MIMEBase('application', 'octet-stream')
|
|
||||||
attachment.set_payload(attach_file.read())
|
attachment.set_payload(attach_file.read())
|
||||||
encoders.encode_base64(attachment)
|
encoders.encode_base64(attachment)
|
||||||
attachment.add_header('Content-Disposition', f'attachment; filename={filename}')
|
attachment.add_header('Content-Disposition', f'attachment; filename={filename}')
|
||||||
|
|
|
@ -3,4 +3,5 @@ From: =?UTF-8?Q?Tr=c3=a9sorier_de_Libre_en_Communs?= <tresorier@a-lec.org>
|
||||||
To: <COURRIEL_DONNEUR>
|
To: <COURRIEL_DONNEUR>
|
||||||
Bcc: <tresorier@a-lec.org>
|
Bcc: <tresorier@a-lec.org>
|
||||||
Subject: =?UTF-8?Q?Libre_en_Communs_:_modalit=c3=a9s_de_r=c3=a8glement_de_votre_don?=
|
Subject: =?UTF-8?Q?Libre_en_Communs_:_modalit=c3=a9s_de_r=c3=a8glement_de_votre_don?=
|
||||||
|
Content-Type: text/plain; charset="UTF-8"
|
||||||
Content-Transfer-Encoding: quoted-printable
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
|
@ -2,4 +2,5 @@ From: tresorier@a-lec.org
|
||||||
To: tresorier@a-lec.org
|
To: tresorier@a-lec.org
|
||||||
Subject: Suivi automatique des dons
|
Subject: Suivi automatique des dons
|
||||||
MIME-Version: 1.0
|
MIME-Version: 1.0
|
||||||
Content-Transfer-Encoding: quoted-printable
|
Content-Type: text/plain; charset="UTF-8"
|
||||||
|
Content-Transfer-Encoding: quoted-printable
|
|
@ -8,4 +8,5 @@ Content-Type: multipart/mixed; boundary="------------3yxkFgv0AINs5nd0i6BJrWaV"
|
||||||
|
|
||||||
This is a multi-part message in MIME format.
|
This is a multi-part message in MIME format.
|
||||||
--------------3yxkFgv0AINs5nd0i6BJrWaV
|
--------------3yxkFgv0AINs5nd0i6BJrWaV
|
||||||
|
Content-Type: text/plain; charset="UTF-8"
|
||||||
Content-Transfer-Encoding: quoted-printable
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
|
@ -78,38 +78,36 @@ def setup_workdir():
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
|
|
||||||
# Send email with attachment via SMTP, password fetched from file
|
# Send email with attachment via SMTP, password fetched from file
|
||||||
def sendmail_with_attachment(headers, data, attachment_path=None, filename=None):
|
def sendmail_with_attachment(headers, body, attachment_path, attachment_filename):
|
||||||
# Create a multipart message
|
|
||||||
msg = MIMEMultipart()
|
msg = MIMEMultipart()
|
||||||
|
|
||||||
# Add the headers without manually setting Content-Type or MIME-Version
|
# Add headers
|
||||||
for header in headers.split("\n"):
|
for header in headers.split("\n"):
|
||||||
if ": " in header and "Content-Type" not in header and "Mime-Version" not in header:
|
if ": " in header:
|
||||||
key, value = header.split(": ", 1)
|
key, value = header.split(": ", 1)
|
||||||
msg[key] = value.strip()
|
msg[key] = value.strip()
|
||||||
|
|
||||||
# Add the email body
|
# Email body
|
||||||
body = MIMEText(data, 'plain', 'utf-8')
|
msg.attach(MIMEText(body, 'plain', 'utf-8'))
|
||||||
msg.attach(body)
|
|
||||||
|
|
||||||
# Add the attachment only if attachment_path is provided
|
# Attach PDF file
|
||||||
if attachment_path and filename:
|
if attachment_path:
|
||||||
with open(attachment_path, "rb") as attach_file:
|
with open(attachment_path, "rb") as attachment:
|
||||||
attachment = MIMEBase('application', 'octet-stream')
|
part = MIMEBase('application', 'octet-stream')
|
||||||
attachment.set_payload(attach_file.read())
|
part.set_payload(attachment.read())
|
||||||
encoders.encode_base64(attachment)
|
encoders.encode_base64(part)
|
||||||
attachment.add_header('Content-Disposition', f'attachment; filename={filename}')
|
part.add_header('Content-Disposition', f'attachment; filename={attachment_filename}')
|
||||||
msg.attach(attachment)
|
msg.attach(part)
|
||||||
|
|
||||||
# Send the email
|
# Send email
|
||||||
try:
|
try:
|
||||||
with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
|
with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
|
||||||
server.starttls() # Start TLS encryption
|
server.starttls() # Secure the connection
|
||||||
server.login(SMTP_USER, smtp_get_secret())
|
server.login(SMTP_USER, smtp_get_secret()) # Fetch SMTP password from file
|
||||||
server.sendmail(SMTP_USER, msg['To'], msg.as_string())
|
server.sendmail(SMTP_USER, msg['To'], msg.as_string())
|
||||||
print("Email sent successfully")
|
print(f"Email sent to {msg['To']}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Failed to send email: {e}")
|
print(f"Error sending email: {e}")
|
||||||
|
|
||||||
# Notify unpaid donors
|
# Notify unpaid donors
|
||||||
def notify_unpaid(record):
|
def notify_unpaid(record):
|
||||||
|
|
Loading…
Reference in New Issue