Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to send email should be retried if it fails #70

Open
dbseraf1 opened this issue Jan 11, 2022 · 2 comments
Open

Attempt to send email should be retried if it fails #70

dbseraf1 opened this issue Jan 11, 2022 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@dbseraf1
Copy link

Currently, if sending email fails because the email server is temporarily offline or overloaded, the only choice of action is to rerun the whole validation. This can be very expensive, and may require manual intervention if the program is running as part of an automatic workflow.

It would be better if the program detected the error in sending email and did its own wait-and-retry loop. This would be pretty cheap and much better than failing.

@colindean colindean added enhancement New feature or request good first issue Good for newcomers labels Jan 11, 2022
@colindean
Copy link
Collaborator

Great suggestion.

Quick notes for myself or whoever may pick this up:

Add config for the retry here:

case class EmailConfig(
smtpHost: String,
subject: String,
from: String,
to: List[String],
cc: Option[List[String]] = None,
bcc: Option[List[String]] = None
) extends EventLog with Substitutable {

Consume the config and handle the retry here:

def sendMessage(message: Message, body: String, mime: String): Boolean = {
message.setContent(body, mime)
val id = message.hashCode().toHexString
try {
logger.info(s"Sending email #$id [${message.getSubject}] to [${message.getAllRecipients.mkString(", ")}]")
Transport.send(message)
logger.info(s"Email #$id sent successfully to all recipients.")
false
}
catch {
case sfe: SendFailedException =>
handleSendFailedException(id, sfe)
true
case me: MessagingException =>
logger.error(s"Failure to send email #$id: $me")
true
}
}

And document it in README.md here:

data-validator/README.md

Lines 74 to 83 in c17ec6a

#### Email Config
| Variable | Type | Required | Description |
|:---|:---|:---|:---:
| `smtpHost` | String | Yes | The smtp host to send email message through.
| `subject` | String | Yes | Subject for email message.
| `from` | String | Yes | Email address to appear in from part of message.
| `to` | Array[String] | Yes | Must specify at least one email address to send the email report to.
| `cc` | Array[String] | No | Optional list of email addresses to send message to via `cc` field in message.
| `bcc` | Array[String] | No | Optional list of email addresses to send message to via `bcc` field in message.

@dougb
Copy link
Collaborator

dougb commented Jan 12, 2022

@dbseraf1 You can save the output to a file or hdfs so you don't lose the results of the run if it fails to send the email.

If you can't wait for this issue to be resolved, you could also use the Pipe output option to specify a program to run which can read the jsonReport from stdin and send an email.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
Development

No branches or pull requests

3 participants