Подпись для почты
Собирает HTML-подпись для письма из имени, должности и контактов.
Что делает скрипт
Скрипт формирует компактную таблицу с именем, ролью, почтой, телефоном и сайтом. Все значения экранируются, поэтому вставка в письмо не ломает разметку. Результат сохраняется в новый HTML-файл и не отправляется по сети.
Быстрый старт
python email_signature.py --name "Анна" --role "Аналитик" --email user@example.com --output signature.html
Скачайте файл, откройте терминал в папке со скриптом и выполните команду.
В Linux и macOS интерпретатор может называться python3, в Windows - python или py.
Другие варианты
python email_signature.py --name "Анна" --role "Аналитик" --email user@example.com --output signature.htmlpython email_signature.py --name "Иван" --role "Разработчик" --email user@example.com --phone "+1 555 0100" --output signature.htmlpython email_signature.py --name "Demo" --email user@example.com --output signature.html --force
Что понадобится
winget install Python.Python.3.12
brew install python
sudo apt install python3
email_signature.py
#!/usr/bin/env python3
"""HTML-подпись для электронной почты."""
from __future__ import annotations
import argparse
import html
import re
from pathlib import Path
ACCENT_RE = re.compile(r"^#[0-9a-fA-F]{6}$")
def build_signature(args: argparse.Namespace) -> str:
name = html.escape(args.name)
role = html.escape(args.role)
email = html.escape(args.email)
phone = html.escape(args.phone)
site = html.escape(args.site)
accent = args.accent
rows = [
f'<div style="font:16px/1.4 Arial,sans-serif;color:#111827"><strong>{name}</strong></div>',
f'<div style="font:13px/1.5 Arial,sans-serif;color:{accent};margin-bottom:8px">{role}</div>',
f'<div style="font:13px/1.6 Arial,sans-serif;color:#374151">'
f'<a href="mailto:{email}" style="color:#111827;text-decoration:none">{email}</a></div>',
]
if args.phone:
rows.append(f'<div style="font:13px/1.6 Arial,sans-serif;color:#374151">{phone}</div>')
if args.site:
rows.append(
f'<div style="font:13px/1.6 Arial,sans-serif">'
f'<a href="{site}" style="color:{accent};text-decoration:none">{site}</a></div>'
)
rows.append(
f'<div style="margin-top:10px;padding-top:8px;border-top:2px solid {accent};'
f'font:12px/1.4 Arial,sans-serif;color:#6b7280">Отправлено из личной почты</div>'
)
return '<table cellpadding="0" cellspacing="0" border="0" role="presentation"><tr><td>' + "".join(rows) + "</td></tr></table>\n"
def main() -> int:
parser = argparse.ArgumentParser(description="HTML-подпись для почты")
parser.add_argument("--name", required=True)
parser.add_argument("--role", default="")
parser.add_argument("--email", required=True)
parser.add_argument("--phone", default="")
parser.add_argument("--site", default="")
parser.add_argument("--accent", default="#c2410c")
parser.add_argument("--output", type=Path, default=Path("signature.html"))
parser.add_argument("--force", action="store_true")
args = parser.parse_args()
if not ACCENT_RE.match(args.accent):
parser.error("--accent указывается в формате #RRGGBB")
output = args.output.expanduser()
if output.suffix.lower() != ".html":
parser.error("Поддерживается только расширение .html")
if output.exists() and not args.force:
parser.error(f"Файл уже существует: {output}. Добавьте --force.")
output.parent.mkdir(parents=True, exist_ok=True)
output.write_text(build_signature(args), encoding="utf-8")
print(f"Подпись сохранена: {output}")
return 0
if __name__ == "__main__":
raise SystemExit(main())
Скрипты работают с файлами и настройками системы. Перед запуском прочитайте код и проверьте пути. Особенно если скрипт удаляет, перезаписывает или перемещает данные.