Aller au contenu principal

Guide : Configuration SMTP dans vos applications

Ce guide explique comment configurer la passerelle SMTP SendAs.me dans les outils et bibliothèques les plus courants.

Paramètres SMTP

Avant de commencer, récupérez vos paramètres SMTP depuis le portail SendAs.me :

ParamètreValeur
Hôte SMTPsmtp.sendas.me
Port587
SécuritéSTARTTLS (obligatoire)
AuthentificationLOGIN
Nom d'utilisateurVotre pushable_key (ex: app_pk_AbCdEfGhIjKlMnOp)
Mot de passeMot de passe SMTP généré dans le portail
Adresse From

L'adresse From de vos e-mails doit correspondre à l'adresse du compte OAuth connecté. Si vous envoyez avec From: alice@gmail.com, le compte Gmail d'Alice doit être connecté à votre application.

Python — smtplib

Envoi simple

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

SMTP_HOST = "smtp.sendas.me"
SMTP_PORT = 587
SMTP_USERNAME = "app_pk_AbCdEfGhIjKlMnOp"
SMTP_PASSWORD = "votre_mot_de_passe_smtp"

def send_email(to: str, subject: str, body_html: str, from_addr: str):
msg = MIMEMultipart("alternative")
msg["Subject"] = subject
msg["From"] = from_addr
msg["To"] = to

# Version texte (fallback)
msg.attach(MIMEText("Veuillez utiliser un client email qui supporte HTML", "plain"))
# Version HTML
msg.attach(MIMEText(body_html, "html"))

with smtplib.SMTP(SMTP_HOST, SMTP_PORT) as server:
server.ehlo()
server.starttls()
server.ehlo()
server.login(SMTP_USERNAME, SMTP_PASSWORD)
server.sendmail(from_addr, [to], msg.as_string())

# Utilisation
send_email(
to="client@example.com",
subject="Bienvenue !",
body_html="<h1>Bienvenue sur notre plateforme</h1>",
from_addr="contact@votreentreprise.com"
)

Avec pièce jointe

import smtplib
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

def send_with_attachment(to: str, subject: str, body: str,
from_addr: str, attachment_path: str):
msg = MIMEMultipart()
msg["Subject"] = subject
msg["From"] = from_addr
msg["To"] = to
msg.attach(MIMEText(body, "html"))

with open(attachment_path, "rb") as f:
part = MIMEApplication(f.read(), Name=attachment_path.split("/")[-1])
part["Content-Disposition"] = f'attachment; filename="{attachment_path.split("/")[-1]}"'
msg.attach(part)

with smtplib.SMTP(SMTP_HOST, SMTP_PORT) as server:
server.starttls()
server.login(SMTP_USERNAME, SMTP_PASSWORD)
server.sendmail(from_addr, [to], msg.as_string())

Node.js — Nodemailer

Installation

npm install nodemailer

Configuration et envoi

const nodemailer = require('nodemailer');

// Créer le transporteur (réutilisable)
const transporter = nodemailer.createTransport({
host: 'smtp.sendas.me',
port: 587,
secure: false, // false = STARTTLS sur port 587
auth: {
user: 'app_pk_AbCdEfGhIjKlMnOp',
pass: 'votre_mot_de_passe_smtp',
},
// Optionnel: désactiver la vérification SSL en dev
// tls: { rejectUnauthorized: false }
});

// Envoyer un e-mail
async function sendEmail() {
const info = await transporter.sendMail({
from: '"Mon App" <contact@votreentreprise.com>',
to: 'client@example.com',
cc: 'copie@example.com', // optionnel
subject: 'Confirmation de votre commande',
text: 'Merci pour votre commande.',
html: `
<h1>Merci pour votre commande !</h1>
<p>Nous traitons votre commande et vous contacterons prochainement.</p>
`,
attachments: [
{
filename: 'facture.pdf',
path: '/chemin/vers/facture.pdf',
},
],
});

console.log('Message envoyé: %s', info.messageId);
return info;
}

sendEmail().catch(console.error);

Avec TypeScript

import nodemailer, { Transporter } from 'nodemailer';

const transporter: Transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST || 'smtp.sendas.me',
port: parseInt(process.env.SMTP_PORT || '587'),
secure: false,
auth: {
user: process.env.SMTP_USERNAME,
pass: process.env.SMTP_PASSWORD,
},
});

export async function sendEmail(options: {
to: string;
subject: string;
html: string;
from?: string;
}): Promise<void> {
await transporter.sendMail({
from: options.from || '"Mon Service" <noreply@votreentreprise.com>',
to: options.to,
subject: options.subject,
html: options.html,
});
}

PHP — PHPMailer

Installation (Composer)

composer require phpmailer/phpmailer

Envoi avec PHPMailer

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

function sendEmail(string $to, string $subject, string $htmlBody): bool
{
$mail = new PHPMailer(true);

try {
// Configuration serveur SMTP
$mail->isSMTP();
$mail->Host = 'smtp.sendas.me';
$mail->SMTPAuth = true;
$mail->Username = 'app_pk_AbCdEfGhIjKlMnOp';
$mail->Password = 'votre_mot_de_passe_smtp';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->CharSet = 'UTF-8';

// Expéditeur et destinataire
$mail->setFrom('contact@votreentreprise.com', 'Mon Application');
$mail->addAddress($to);

// Contenu
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $htmlBody;
$mail->AltBody = strip_tags($htmlBody);

$mail->send();
return true;
} catch (Exception $e) {
error_log("Erreur envoi email: {$mail->ErrorInfo}");
return false;
}
}

// Utilisation
sendEmail(
'client@example.com',
'Votre facture du mois',
'<h1>Facture disponible</h1><p>Votre facture est disponible.</p>'
);

Postfix comme relay

Si vous utilisez Postfix pour relayer tous vos e-mails système vers SendAs.me :

/etc/postfix/main.cf

# Relay SMTP vers SendAs.me
relayhost = [smtp.sendas.me]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_use_tls = yes
smtp_tls_security_level = encrypt
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

/etc/postfix/sasl_passwd

[smtp.sendas.me]:587    app_pk_AbCdEfGhIjKlMnOp:votre_mot_de_passe_smtp

Appliquer la configuration

sudo postmap /etc/postfix/sasl_passwd
sudo chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
sudo systemctl reload postfix

Django (Python)

Dans settings.py :

# Configuration email Django
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.sendas.me'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
EMAIL_HOST_USER = 'app_pk_AbCdEfGhIjKlMnOp'
EMAIL_HOST_PASSWORD = 'votre_mot_de_passe_smtp'
DEFAULT_FROM_EMAIL = 'contact@votreentreprise.com'

Envoi :

from django.core.mail import send_mail

send_mail(
subject='Bienvenue',
message='Merci de vous être inscrit.',
from_email='contact@votreentreprise.com',
recipient_list=['user@example.com'],
html_message='<h1>Bienvenue !</h1>',
)

Ruby on Rails

Dans config/environments/production.rb :

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.sendas.me',
port: 587,
domain: 'votreentreprise.com',
user_name: 'app_pk_AbCdEfGhIjKlMnOp',
password: 'votre_mot_de_passe_smtp',
authentication: 'login',
enable_starttls_auto: true
}

Variables d'environnement recommandées

Ne stockez jamais les credentials SMTP directement dans votre code. Utilisez des variables d'environnement :

# .env de votre application cliente
SENDAS_SMTP_HOST=smtp.sendas.me
SENDAS_SMTP_PORT=587
SENDAS_SMTP_USERNAME=app_pk_AbCdEfGhIjKlMnOp
SENDAS_SMTP_PASSWORD=votre_mot_de_passe_smtp
EMAIL_FROM=contact@votreentreprise.com
Rotation du mot de passe

Si vous suspectez que votre mot de passe SMTP a été compromis, régénérez-en un nouveau immédiatement via le portail SendAs.me (POST /apps/{pushable_key}/reset-smtp-password). L'ancien mot de passe est invalidé instantanément.