Skip to content

Resending Failed Outgoing Messages

Gareth Rees edited this page Jul 23, 2018 · 2 revisions

This is generally highlighted by an internal error, last_event_forming_initial_request gets nil for request REQUEST_ID outgoing messages count 1 all events error.

# Find messages that are unsent. Note that one of these will probably be the
# holding pen.
OutgoingMessage.where(:status => 'ready')

# Handle one at a time
message = OutgoingMessage.where(:status => 'ready').last

# Take a look at the info request associated with each one.
message.info_request

# Decide what to do.
#
# A. Destroy it:
message.info_request.destroy

# B. Resend the message. If its an initial request, use
#    OutgoingMailer.initial_request
if message.sendable?
  mail_message = OutgoingMailer.initial_request(
    message.info_request,
    message
  ).deliver

  message.record_email_delivery(
    mail_message.to_addrs.join(', '),
    mail_message.message_id
  )
end

# If it's a followup, use OutgoingMailer.followup
if message.sendable?
  mail_message = OutgoingMailer.followup(
    message.info_request,
    message,
    message.incoming_message_followup
  ).deliver

  message.record_email_delivery(
    mail_message.to_addrs.join(', '),
    mail_message.message_id
  )
end
Clone this wiki locally