email-module-sender 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- email_module_sender-1.1.0/PKG-INFO +11 -0
- email_module_sender-1.1.0/README.md +3 -0
- email_module_sender-1.1.0/pyproject.toml +19 -0
- email_module_sender-1.1.0/setup.cfg +4 -0
- email_module_sender-1.1.0/src/email_module/__init__.py +8 -0
- email_module_sender-1.1.0/src/email_module/sender.py +152 -0
- email_module_sender-1.1.0/src/email_module_sender.egg-info/PKG-INFO +11 -0
- email_module_sender-1.1.0/src/email_module_sender.egg-info/SOURCES.txt +8 -0
- email_module_sender-1.1.0/src/email_module_sender.egg-info/dependency_links.txt +1 -0
- email_module_sender-1.1.0/src/email_module_sender.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: email-module-sender
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Simple email sender module
|
|
5
|
+
Author: Yassine SEFFAR
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
# Email Module Sender
|
|
10
|
+
|
|
11
|
+
A simple Python email sending module.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "email-module-sender"
|
|
7
|
+
version = "1.1.0"
|
|
8
|
+
description = "Simple email sender module"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
authors = [
|
|
12
|
+
{ name="Yassine SEFFAR" }
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[tool.setuptools]
|
|
16
|
+
package-dir = {"" = "src"}
|
|
17
|
+
|
|
18
|
+
[tool.setuptools.packages.find]
|
|
19
|
+
where = ["src"]
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import smtplib
|
|
2
|
+
import mimetypes
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from email.message import EmailMessage
|
|
5
|
+
from typing import Union, Tuple, List
|
|
6
|
+
from functools import lru_cache
|
|
7
|
+
|
|
8
|
+
@lru_cache(maxsize=128)
|
|
9
|
+
def get_mime_type(filename: str) -> Tuple[str, str]:
|
|
10
|
+
"""Retourne (maintype, subtype) avec cache."""
|
|
11
|
+
mime_type, _ = mimetypes.guess_type(filename)
|
|
12
|
+
if mime_type is None:
|
|
13
|
+
mime_type = "application/octet-stream"
|
|
14
|
+
return tuple(mime_type.split("/", 1))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def SendEmail(
|
|
18
|
+
from_email: str,
|
|
19
|
+
password: str,
|
|
20
|
+
to: Union[str, List[str]], # ← Accepte string OU liste
|
|
21
|
+
subject: str,
|
|
22
|
+
text: str = None,
|
|
23
|
+
text_color: Union[str, Tuple[int, int, int]] = None,
|
|
24
|
+
text_size: Union[int, str] = 16,
|
|
25
|
+
text_font: str = "Arial, sans-serif",
|
|
26
|
+
html: str = None,
|
|
27
|
+
cc: Union[str, List[str]] = None, # ← Accepte string OU liste
|
|
28
|
+
bcc: Union[str, List[str]] = None, # ← Accepte string OU liste
|
|
29
|
+
attachments: Union[str, List[str]] = None, # ← Accepte string OU liste
|
|
30
|
+
smtp_server: str = "smtp.gmail.com",
|
|
31
|
+
smtp_port: int = 587,
|
|
32
|
+
timeout: int = 30
|
|
33
|
+
):
|
|
34
|
+
"""
|
|
35
|
+
Envoie un email avec options de style avancées.
|
|
36
|
+
|
|
37
|
+
Parameters:
|
|
38
|
+
- from_email : adresse email de l'expéditeur
|
|
39
|
+
- password : mot de passe ou app password SMTP
|
|
40
|
+
- to : destinataire(s) - string ou liste (ex: "user@example.com" ou ["user@example.com"])
|
|
41
|
+
- subject : sujet de l'email
|
|
42
|
+
- text : contenu texte simple
|
|
43
|
+
- text_color : couleur du texte ('red', '#ff0000', ou (255,0,0))
|
|
44
|
+
- text_size : taille du texte en px (ex: 16, "18px", "1.2em")
|
|
45
|
+
- text_font : police du texte (ex: "Arial", "Georgia, serif")
|
|
46
|
+
- html : HTML personnalisé complet (ignore text/color/size/font)
|
|
47
|
+
- cc : copie carbone - string ou liste
|
|
48
|
+
- bcc : copie carbone invisible - string ou liste
|
|
49
|
+
- attachments : fichier(s) à joindre - string ou liste (ex: "file.pdf" ou ["file.pdf"])
|
|
50
|
+
- smtp_server : serveur SMTP (par défaut Gmail)
|
|
51
|
+
- smtp_port : port SMTP (587 pour TLS)
|
|
52
|
+
- timeout : timeout de connexion en secondes
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
# Conversion automatique en listes
|
|
56
|
+
if isinstance(to, str):
|
|
57
|
+
to = [to]
|
|
58
|
+
if isinstance(cc, str):
|
|
59
|
+
cc = [cc]
|
|
60
|
+
if isinstance(bcc, str):
|
|
61
|
+
bcc = [bcc]
|
|
62
|
+
if isinstance(attachments, str):
|
|
63
|
+
attachments = [attachments]
|
|
64
|
+
|
|
65
|
+
# Valeurs par défaut
|
|
66
|
+
cc = cc or []
|
|
67
|
+
bcc = bcc or []
|
|
68
|
+
attachments = attachments or []
|
|
69
|
+
|
|
70
|
+
# Validations
|
|
71
|
+
if not to:
|
|
72
|
+
raise ValueError("La liste 'to' ne peut pas être vide")
|
|
73
|
+
if not (text or html):
|
|
74
|
+
raise ValueError("Il faut fournir 'text' ou 'html'")
|
|
75
|
+
|
|
76
|
+
# Création du message
|
|
77
|
+
msg = EmailMessage()
|
|
78
|
+
msg["From"] = from_email
|
|
79
|
+
msg["To"] = ", ".join(to)
|
|
80
|
+
msg["Subject"] = subject
|
|
81
|
+
|
|
82
|
+
if cc:
|
|
83
|
+
msg["Cc"] = ", ".join(cc)
|
|
84
|
+
|
|
85
|
+
# ----- CONTENU -----
|
|
86
|
+
if html:
|
|
87
|
+
msg.set_content("Votre client email ne supporte pas le HTML.")
|
|
88
|
+
msg.add_alternative(html, subtype="html")
|
|
89
|
+
|
|
90
|
+
elif text:
|
|
91
|
+
# Traitement de la couleur
|
|
92
|
+
color = "black"
|
|
93
|
+
if text_color:
|
|
94
|
+
if isinstance(text_color, tuple):
|
|
95
|
+
if len(text_color) != 3:
|
|
96
|
+
raise ValueError("text_color tuple doit être (R, G, B)")
|
|
97
|
+
color = f"rgb({text_color[0]},{text_color[1]},{text_color[2]})"
|
|
98
|
+
else:
|
|
99
|
+
color = text_color
|
|
100
|
+
|
|
101
|
+
# Traitement de la taille
|
|
102
|
+
if isinstance(text_size, int):
|
|
103
|
+
size = f"{text_size}px"
|
|
104
|
+
else:
|
|
105
|
+
size = text_size
|
|
106
|
+
|
|
107
|
+
# Remplacement des sauts de ligne
|
|
108
|
+
text_html = text.replace("\n", "<br>")
|
|
109
|
+
|
|
110
|
+
# Génération du HTML
|
|
111
|
+
html_content = f"""<!DOCTYPE html>
|
|
112
|
+
<html>
|
|
113
|
+
<head>
|
|
114
|
+
<meta charset="UTF-8">
|
|
115
|
+
</head>
|
|
116
|
+
<body>
|
|
117
|
+
<p style="color: {color}; font-size: {size}; font-family: {text_font}; line-height: 1.6;">
|
|
118
|
+
{text_html}
|
|
119
|
+
</p>
|
|
120
|
+
</body>
|
|
121
|
+
</html>"""
|
|
122
|
+
|
|
123
|
+
msg.set_content(text)
|
|
124
|
+
msg.add_alternative(html_content, subtype="html")
|
|
125
|
+
|
|
126
|
+
# ----- PIÈCES JOINTES -----
|
|
127
|
+
if attachments:
|
|
128
|
+
paths = []
|
|
129
|
+
for file in attachments:
|
|
130
|
+
path = Path(file)
|
|
131
|
+
if not path.exists():
|
|
132
|
+
raise FileNotFoundError(f"Fichier introuvable : {file}")
|
|
133
|
+
paths.append(path)
|
|
134
|
+
|
|
135
|
+
for path in paths:
|
|
136
|
+
maintype, subtype = get_mime_type(path.name)
|
|
137
|
+
|
|
138
|
+
with open(path, "rb") as f:
|
|
139
|
+
msg.add_attachment(
|
|
140
|
+
f.read(),
|
|
141
|
+
maintype=maintype,
|
|
142
|
+
subtype=subtype,
|
|
143
|
+
filename=path.name
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
# ----- ENVOI -----
|
|
147
|
+
all_recipients = to + cc + bcc
|
|
148
|
+
|
|
149
|
+
with smtplib.SMTP(smtp_server, smtp_port, timeout=timeout) as server:
|
|
150
|
+
server.starttls()
|
|
151
|
+
server.login(from_email, password)
|
|
152
|
+
server.send_message(msg, to_addrs=all_recipients)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: email-module-sender
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Simple email sender module
|
|
5
|
+
Author: Yassine SEFFAR
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
# Email Module Sender
|
|
10
|
+
|
|
11
|
+
A simple Python email sending module.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/email_module/__init__.py
|
|
4
|
+
src/email_module/sender.py
|
|
5
|
+
src/email_module_sender.egg-info/PKG-INFO
|
|
6
|
+
src/email_module_sender.egg-info/SOURCES.txt
|
|
7
|
+
src/email_module_sender.egg-info/dependency_links.txt
|
|
8
|
+
src/email_module_sender.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
email_module
|