| | 16 | |
|---|
| | 17 | # Constant: MAX_DELIVERY_ATTEMPTS |
|---|
| | 18 | # =============================== |
|---|
| | 19 | # The maximum number of mail delivery attemps made by the <deliver!> |
|---|
| | 20 | # method when delivery fails with a "temporary" error code. |
|---|
| | 21 | # |
|---|
| | 22 | MAX_DELIVERY_ATTEMPTS = 10 |
|---|
| | 23 | |
|---|
| | 24 | # Method: deliver! |
|---|
| | 25 | # ================ |
|---|
| | 26 | # Does the same as the original implementation is the Base class. |
|---|
| | 27 | # In addition rescues exceptions raised by Net::SMTP and also |
|---|
| | 28 | # some raised by TCPSocket. The errors are logged and "forgotten". |
|---|
| | 29 | # |
|---|
| | 30 | def deliver!(*args) |
|---|
| | 31 | begin |
|---|
| | 32 | super(*args) |
|---|
| | 33 | rescue Net::SMTPServerBusy => e |
|---|
| | 34 | # Try again MAX_DELIVERY_ATTEMPTS times |
|---|
| | 35 | @delivery_attempt_count ||= 0 |
|---|
| | 36 | if @delivery_attempt_count < MAX_DELIVERY_ATTEMPTS |
|---|
| | 37 | @delivery_attempt_count += 1 |
|---|
| | 38 | deliver!(*args) |
|---|
| | 39 | end |
|---|
| | 40 | CmmsMailerBase._error("SMTP server busy: #{e}. Failed to deliver mail.") |
|---|
| | 41 | # Reset counter |
|---|
| | 42 | @delivery_attempt_count = 0 |
|---|
| | 43 | rescue TimeoutError => e |
|---|
| | 44 | CmmsMailerBase._error("Timeout error: #{e}. Failed to deliver mail.") |
|---|
| | 45 | rescue Net::SMTPAuthenticationError => e |
|---|
| | 46 | CmmsMailerBase._error("SMTP authentication error: #{e}. Failed to deliver mail.") |
|---|
| | 47 | rescue Net::SMTPSyntaxError => e |
|---|
| | 48 | CmmsMailerBase._error("SMTP syntax error: #{e}. Failed to deliver mail.") |
|---|
| | 49 | rescue Net::SMTPFatalError => e |
|---|
| | 50 | CmmsMailerBase._error("SMTP fatal error: #{e}. Failed to deliver mail.") |
|---|
| | 51 | rescue Net::SMTPUnknownError => e |
|---|
| | 52 | CmmsMailerBase._error("SMTP unknown error: #{e}. Failed to deliver mail.") |
|---|
| | 53 | rescue Errno::ECONNREFUSED => e |
|---|
| | 54 | # Raised by TCPSocket when SMTP server is not found on GNU/Linux. |
|---|
| | 55 | CmmsMailerBase._error("TCP socket error: #{e}. Failed to deliver mail.") |
|---|
| | 56 | rescue Errno::EBADF => e |
|---|
| | 57 | # Raised by TCPSocket when SMTP server is not found on Windows XP. |
|---|
| | 58 | CmmsMailerBase._error("TCP socket error: #{e}. Failed to deliver mail.") |
|---|
| | 59 | end |
|---|
| | 60 | end |
|---|