Bonjour,
NB 1 : C'est ma première question Python, jusqu'ici je codais en Perl
NB 2 : Donc je suis plus que nul en Python
NB 3 : Je dois envoyer rapidement un mail depuis Arch Linux et en Python, car MIME:Lite n'est pas disponible sur le Perl Arch (This is perl 5, version 40, subversion 2 (v5.40.2) built for x86_64-linux-thread-multi), alors que je l'utilise sans pb en Perl Strawberry sous Win 7 et Win11

Bout de mon code, le plus gros pompé sur le net :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import smtplib
import subprocess
from os.path import basename
import email.message
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
#import base64
 
# OK
# https://forwardemail.net/en/guides/smtp-integration#python-integration
# Email configuration
sender_email = "smtp.free.fr"
receiver_email = "xxxx@free.fr"
password = "xxxx"
 
NbFic=subprocess.run("ls -l /root/FS_NTFS/SAVE/Bookmarks | grep bookmarks | wc -l", shell=True, capture_output=True, text=True)
chaine = "ATTENTION, il y a {} fichiers Bookmark.html dans /root/FS_NTFS/SAVE/Bookmarks".format(NbFic.stdout.strip());
 
#bchaine = base64.b64encode(bytes(chaine, 'utf-8')) # bytes
#base64_str = bchaine.decode('utf-8') # convert bytes to string
 
# Create message
message = MIMEMultipart()
message["Subject"] = chaine
message["From"] = "xxxx@free.fr"
message["To"] = "xxxx@free.fr"
Si je code un sujet en dur ça passe :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
message["Subject"] = "Hello World comme dans tous les exemples..."
 
#> python Smtp.py
Email sent successfully!
Si je construis mon sujet :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
NbFic=subprocess.run("ls -l /root/FS_NTFS/SAVE/Bookmarks | grep bookmarks | wc -l", shell=True, capture_output=True, text=True)
chaine = "ATTENTION, il y a {} fichiers Bookmark.html dans /root/FS_NTFS/SAVE/Bookmarks".format(NbFic.stdout.strip());
 
message["Subject"] = chaine
Le mail part bien, mais free détecte du spam ? :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
#> python Smtp.py
Error sending email: (550, b'5.7.1 Spam Detected - Mail Rejected.  Please see our policy at: http://postmaster.free.fr/#spam_detected')
Alors que ma chaine se construit correctement Ess_2.py :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import os
import subprocess
 
# Sujet
# NbFic=os.system('ls -l /root/FS_NTFS/SAVE/Bookmarks | grep bookmarks | wc -l')
# print(NbFic)
 
NbFic=subprocess.run("ls -l /root/FS_NTFS/SAVE/Bookmarks | grep bookmarks | wc -l", shell=True, capture_output=True, text=True)
# print(NbFic.stdout)
 
# Afficher la sortie
# result = NbFic.strip()
 
chaine = "ATTENTION, il y a {} fichiers Bookmark.html dans /root/FS_NTFS/SAVE/Bookmarks".format(NbFic.stdout.strip());
print(chaine)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
#> python Ess_2.py
ATTENTION, il y a 7 fichiers Bookmark.html dans /root/FS_NTFS/SAVE/Bookmarks

J'ai essayé au pif quelques conversions base64... Mais vaudrait mieux quelqu'un qui sait

Pouvez-vous venir à mon secours en attendant que je me mette correctement à Python ?
MERCI !