Mode de requête SMTP

Le processus de session est le suivant.

S: 220 Serveur entrant EngageLab ESMTP Haraka 2.2.4 prêt C: ehlo ifaxin.com S: 250-Serveur entrant EngageLab Bonjour, Haraka est à votre service. S: 250-PIPELINING S: 250-8BITMIME S: 250-SIZE 16000000 S: 250 AUTH LOGIN C: AUTH LOGIN base64(api_user) S: 334 UGFzc3dvcmQ6 C: base64(api_key) S: 235 Authentification réussie C: mail FROM:<support@ifaxin.com> S: 250 expéditeur <support@ifaxin.com> OK C: rcpt TO:<ben@ifaxin.com> S: 250 destinataire <ben@ifaxin.com> OK C: data S: 354 allez-y, faites ma journée C: ... ... C: . S: 250 #1426390015358_15_6484_8661.sc-10_10_127_51-inbound#En file d'attente C: quit S: 221 Serveur entrant EngageLab fermeture de la connexion. Passez une excellente journée
              
              S: 220 Serveur entrant EngageLab ESMTP Haraka 2.2.4 prêt

C: ehlo ifaxin.com

S: 250-Serveur entrant EngageLab Bonjour, Haraka est à votre service.
S: 250-PIPELINING
S: 250-8BITMIME
S: 250-SIZE 16000000
S: 250 AUTH LOGIN

C: AUTH LOGIN base64(api_user)

S: 334 UGFzc3dvcmQ6

C: base64(api_key)

S: 235 Authentification réussie

C: mail FROM:<support@ifaxin.com>

S: 250 expéditeur <support@ifaxin.com> OK

C: rcpt TO:<ben@ifaxin.com>

S: 250 destinataire <ben@ifaxin.com> OK

C: data

S: 354 allez-y, faites ma journée

C: ... ...
C: .

S: 250 #1426390015358_15_6484_8661.sc-10_10_127_51-inbound#En file d'attente

C: quit

S: 221 Serveur entrant EngageLab fermeture de la connexion. Passez une excellente journée

            
Afficher ce bloc de code dans la fenêtre flottante

Remarque : l'appel SMTP retourne 536 limitation de fréquence, ce qui signifie que le nombre total d'appels API et SMTP par apiuser par minute ne peut pas dépasser 30 000 fois.

Utilisation de la fonction label pour l'accès SMTP

Lors de la vérification, l'ID de label est concaténé après API_USER.

api_user + '#' + label_id

Sans label :

S: 250-Serveur entrant EngageLab Bonjour, Haraka est à votre service. S: 250-PIPELINING S: 250-8BITMIME S: 250-SIZE 16000000 S: 250-STARTTLS S: 250 AUTH LOGIN C: AUTH LOGIN base64(api_user)
              
              S: 250-Serveur entrant EngageLab Bonjour, Haraka est à votre service.
S: 250-PIPELINING
S: 250-8BITMIME
S: 250-SIZE 16000000
S: 250-STARTTLS
S: 250 AUTH LOGIN

C: AUTH LOGIN base64(api_user)

            
Afficher ce bloc de code dans la fenêtre flottante

Avec label :

S: 250-Serveur entrant EngageLab Bonjour, Haraka est à votre service. S: 250-PIPELINING S: 250-8BITMIME S: 250-SIZE 16000000 S: 250-STARTTLS S: 250 AUTH LOGIN C: AUTH LOGIN base64(api_user + '#' + label_id)
              
              S: 250-Serveur entrant EngageLab Bonjour, Haraka est à votre service.
S: 250-PIPELINING
S: 250-8BITMIME
S: 250-SIZE 16000000
S: 250-STARTTLS
S: 250 AUTH LOGIN

C: AUTH LOGIN base64(api_user + '#' + label_id)

            
Afficher ce bloc de code dans la fenêtre flottante

Extrait de code Python :

# sans label : s = SMTP('%s:%d' % (HOST, PORT)) s.set_debuglevel(DEBUG_MODE) if USE_SSL: s.starttls() s.login(API_USER, API_KEY) # avec label : s = SMTP('%s:%d' % (HOST, PORT)) s.set_debuglevel(DEBUG_MODE) if USE_SSL: s.starttls() s.login(API_USER + '#' + label_id, API_KEY)
              
              # sans label :
s = SMTP('%s:%d' % (HOST, PORT))
s.set_debuglevel(DEBUG_MODE)
if USE_SSL:
    s.starttls()
s.login(API_USER, API_KEY)

# avec label :
s = SMTP('%s:%d' % (HOST, PORT))
s.set_debuglevel(DEBUG_MODE)
if USE_SSL:
    s.starttls()
s.login(API_USER + '#' + label_id, API_KEY)

            
Afficher ce bloc de code dans la fenêtre flottante

Envoyer des images intégrées par SMTP

Exemple de code :

from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.image import MIMEImage import smtplib class MyEmail: def __init__(self): self.smtp = smtplib.SMTP() self.login_username = 'postmaster@testdomain' self.login_password = '*****' self.sender = 'postmaster@testdomain' # identique à login_username self.receiver = 'test123@qq.com' self.host = 'smtp.engagelab.net' self.port = 25 def connect(self): self.smtp.connect(self.host) def login(self): self.smtp.login(self.login_username, self.login_password) def send(self): msg = MIMEMultipart('related') msg['From'] = self.sender msg['To'] = self.receiver email_title = 'test python image intégrée' msg['Subject'] = email_title content = MIMEText('test image content <img src="cid:image1" alt="xxxxx">', 'html', 'utf-8') msg.attach(content) fp = open('./test.png','rb') img = MIMEImage(fp.read()) img.add_header('Content-ID','image1') # la valeur de content-id est le cid dans le html msg.attach(img) self.smtp.sendmail(self.sender, self.receiver, msg.as_string()) def quit(self): self.smtp.quit() def send(): myemail = MyEmail() myemail.connect() myemail.login() myemail.send() myemail.quit() if __name__ == "__main__": send()
              
              from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
import smtplib

class MyEmail:
    def __init__(self):
        self.smtp = smtplib.SMTP()
        self.login_username = 'postmaster@testdomain'
        self.login_password = '*****'
        self.sender = 'postmaster@testdomain'    # identique à login_username
        self.receiver = 'test123@qq.com'
        self.host = 'smtp.engagelab.net'
        self.port = 25

    def connect(self):
        self.smtp.connect(self.host)

    def login(self):
        self.smtp.login(self.login_username, self.login_password)

    def send(self):
        msg = MIMEMultipart('related')
        msg['From'] = self.sender
        msg['To'] = self.receiver
        email_title = 'test python image intégrée'
        msg['Subject'] = email_title
        content = MIMEText('test image content <img src="cid:image1" alt="xxxxx">', 'html', 'utf-8')
        msg.attach(content)

        fp = open('./test.png','rb')
        img = MIMEImage(fp.read())
        img.add_header('Content-ID','image1') # la valeur de content-id est le cid dans le html
        msg.attach(img)

        self.smtp.sendmail(self.sender, self.receiver, msg.as_string())

    def quit(self):
        self.smtp.quit()

def send():
    myemail = MyEmail()
    myemail.connect()
    myemail.login()
    myemail.send()
    myemail.quit()

if __name__ == "__main__":
    send()

            
Afficher ce bloc de code dans la fenêtre flottante

Requêtes du protocole SMTP pour l'envoi de mails chiffrés

La faille indique que SSL V3.0 n'est plus du tout sécurisé, donc les utilisateurs peuvent accéder au protocole de chiffrement via SMTP, qui supporte tls-v1.0-v1.2, et ne supporte pas SSL 3.0 ou antérieur. Les ports 25 supportent le chiffrement starttls. Les utilisateurs doivent ajouter une ligne de code de chiffrement, par exemple en Java : props.setProperty("mail.smtp.starttls.enable", "true");

icon
Contactez-nous