Mail and Bounced Emails

2009-09-18 21:30:13 +0000

You might have to deal with bounced emails in your application. The new mail library makes this a no brainer…

I like code more than words… so:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
require 'mail'

@mail = Mail.read('/path/to/bounce_message.eml')

# You can also do Mail.new('String of email message')

@mail.bounced?
#=> true
@mail.final_recipient
#=> rfc822;mikel@dont.exist.com
@mail.action
#=> failed
@mail.error_status
#=> 5.5.0
@mail.diagnostic_code  
#=> smtp;550 Requested action not taken: mailbox unavailable 
@mail.retryable?
#=> false

You can get mail from my GitHub repository

Once we finish a few more points in the library, I’ll release a gem.

Mikel