slimta.bounce

class slimta.bounce.Bounce(envelope, reply[, headers_only=False])

Bases: slimta.envelope.Envelope

Class that inherits Envelope to implement a bounce message, which is then delivered back to the original sender to say the message failed to deliver. The original message body is attached to the bounce message.

Parameters:
  • envelope – The Envelope object of the original failed message.
  • reply – The Reply object that caused the failure.
  • headers_only – If given True, the bounce will include only the only the original message’s headers, not the entire message body.
sender = ''

The address to use as the sender of new bounce messages. Per SMTP RFCs, this should usually be an empty string.

header_template = b'From: MAILER-DAEMON\r\nTo: {sender}\r\nSubject: Undelivered Mail Returned to Sender\r\nAuto-Submitted: auto-replied\r\nMIME-Version: 1.0\r\nContent-Type: multipart/report; report-type=delivery-status;\r\n boundary="{boundary}"\r\nContent-Transfer-Encoding: 7bit\r\n\r\nThis is a multi-part message in MIME format.\r\n\r\n--{boundary}\r\nContent-Type: text/plain\r\n\r\nDelivery failed for:\r\n- {recipients}\r\n\r\nDestination host responded:\r\n{code} {message}\r\n\r\n--{boundary}\r\nContent-Type: message/delivery-status\r\n\r\n{delivery_info}\r\n\r\n--{boundary}\r\nContent-Type: {content_type}\r\n\r\n'

Template to use for the bounce message data, inserted directly before the original message data. The template is processed with BytesFormat.format() with the following keys:

  • boundary – A randomly generated MIME boundary string.
  • sender – The sender of the original message.
  • recipients – The recipients list, rendered by joining the
    recipients list with recipient_join.
  • client_name – The hostname of the original message sending
    client.
  • client_ip – The IP address of the original message sending
    client.
  • protocol – The protocol used to deliver the original message.
  • code – The SMTP reply code that caused the message failure.
  • message – The SMTP reply message that caused the message failure.
recipient_join = '\r\n- '

When bouncing a message that was going to multiple recipients, this string is used to join the list of recipients for the {recipients} template key.

footer_template = b'\r\n--{boundary}--\r\n'

Template used to add text below the original message data. This template is processed the same way as header_template.

client = {'host': 'localhost', 'ip': '127.0.0.1', 'name': 'postmaster'}

The client information used when sending bounce messages. Injected as the client attribute of bounce messages.

receiver = None

String injected as the receiver attribute of bounce messages. By default, this value is copied from the Envelope itself.