Modo de solicitud SMTP
A continuación se muestra el proceso de sesión.
S: 220 EngageLab Inbound Server ESMTP Haraka 2.2.4 ready
C: ehlo ifaxin.com
S: 250-EngageLab Inbound Server Hello, Haraka is at your 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 Authentication successful
C: mail FROM:<support@ifaxin.com>
S: 250 sender <support@ifaxin.com> OK
C: rcpt TO:<ben@ifaxin.com>
S: 250 recipient <ben@ifaxin.com> OK
C: data
S: 354 go ahead, make my day
C: ... ...
C: .
S: 250 #1426390015358_15_6484_8661.sc-10_10_127_51-inbound#Queued
C: quit
S: 221 EngageLab Inbound Server closing connection. Have a jolly good day
S: 220 EngageLab Inbound Server ESMTP Haraka 2.2.4 ready
C: ehlo ifaxin.com
S: 250-EngageLab Inbound Server Hello, Haraka is at your 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 Authentication successful
C: mail FROM:<support@ifaxin.com>
S: 250 sender <support@ifaxin.com> OK
C: rcpt TO:<ben@ifaxin.com>
S: 250 recipient <ben@ifaxin.com> OK
C: data
S: 354 go ahead, make my day
C: ... ...
C: .
S: 250 #1426390015358_15_6484_8661.sc-10_10_127_51-inbound#Queued
C: quit
S: 221 EngageLab Inbound Server closing connection. Have a jolly good day
Este bloque de código se muestra en una ventana flotante
Nota: si la llamada SMTP devuelve 536 (límite de frecuencia), significa que el número total de llamadas API y SMTP por apiuser por minuto no puede superar las 30.000 solicitudes.
Uso de la función de etiqueta para el acceso SMTP
Durante la verificación, se concatena el ID de etiqueta después de API_USER.
api_user + '#' + label_id
Sin etiqueta:
S: 250-EngageLab Inbound Server Hello, Haraka is at your 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-EngageLab Inbound Server Hello, Haraka is at your service.
S: 250-PIPELINING
S: 250-8BITMIME
S: 250-SIZE 16000000
S: 250-STARTTLS
S: 250 AUTH LOGIN
C: AUTH LOGIN base64(api_user)
Este bloque de código se muestra en una ventana flotante
Con etiqueta:
S: 250-EngageLab Inbound Server Hello, Haraka is at your 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-EngageLab Inbound Server Hello, Haraka is at your 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)
Este bloque de código se muestra en una ventana flotante
Fragmento de código Python:
# without label:
s = SMTP('%s:%d' % (HOST, PORT))
s.set_debuglevel(DEBUG_MODE)
if USE_SSL:
s.starttls()
s.login(API_USER, API_KEY)
# with 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)
# without label:
s = SMTP('%s:%d' % (HOST, PORT))
s.set_debuglevel(DEBUG_MODE)
if USE_SSL:
s.starttls()
s.login(API_USER, API_KEY)
# with 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)
Este bloque de código se muestra en una ventana flotante
Envío de imágenes incrustadas mediante SMTP
Ejemplos de código:
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' # same as 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 = 'python test inline image'
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') #the value of content-id is the cid in 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' # same as 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 = 'python test inline image'
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') #the value of content-id is the cid in 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()
Este bloque de código se muestra en una ventana flotante
Solicitudes del protocolo SMTP para el envío de correo cifrado
La vulnerabilidad POODLE indica que SSL v3.0 es completamente inseguro en la actualidad. Por lo tanto, se puede acceder al protocolo de cifrado a través de SMTP, que admite TLS v1.0 a v1.2, y no admite SSL 3.0 ni versiones anteriores.
El puerto 25 admite el cifrado STARTTLS. Es necesario añadir un fragmento de código de cifrado, por ejemplo, en Java:
props.setProperty("mail.smtp.starttls.enable", "true");
props.setProperty("mail.smtp.starttls.enable", "true");
Este bloque de código se muestra en una ventana flotante

