Skip to content

Email notification for cert expiry#204

Open
garaimanoj wants to merge 10 commits into
stfc:masterfrom
garaimanoj:GT-1437-email-notification-for-cert-expiry
Open

Email notification for cert expiry#204
garaimanoj wants to merge 10 commits into
stfc:masterfrom
garaimanoj:GT-1437-email-notification-for-cert-expiry

Conversation

@garaimanoj
Copy link
Copy Markdown
Contributor

@garaimanoj garaimanoj commented Apr 24, 2026

2026-04-27T09:57:00.193+01:00  INFO 423739 --- [iry-scheduler-1] uk.ac.ngs.TaskConfig                     : Starting daily certificate expiry reminder job
2026-04-27T09:57:00.461+01:00  INFO 423739 --- [iry-scheduler-1] uk.ac.ngs.service.CertificateService     : 1 certificate(s) are going to expire after 7 days.
2026-04-27T09:57:00.463+01:00  INFO 423739 --- [iry-scheduler-1] uk.ac.ngs.service.CertificateService     : Sending 7-days expiry reminder for cert [103] to bob13@xyzc.com
2026-04-27T09:57:02.053+01:00  INFO 423739 --- [iry-scheduler-1] u.a.n.s.email.FreemarkerEmailSender      : body=<!doctype html>

<html>

<body>
    Dear Owner of UK e-Science Certificate number: 103,
    <br />
    <br />
    You have a certificate which will expire in <b>7 days</b>. If you do not wish to renew this
    certificates or if you have
    done so already then please ignore this message.
    <br />
    <br />
    Your certificate was issued for "User3" and has the subject:
    <br />
    <br />
    [CN=User1,OU=xyz_c,O=stfc.com,L=OX,ST=OX,C=UK]
    <br />
    <br />
    If you prefer a browser interface for your certificate management and you have your current certificate in your
    browser then please go to the CA Portal <a href="https://portal.ca.grid-support.ac.uk/">https://portal.ca.grid-support.ac.uk/</a> and follow the instructions
    for renewal.
    <br />
    <br />
    Other tools are available at <a href="https://ca.grid-support.ac.uk">https://ca.grid-support.ac.uk</a>
    <br />
    <br />
    The server will then queue your renewal request for your RA to approve.
    There is NO need to visit your RA. You will receive an e-mail when the certificate is available.
    <br />
    <br />
    If you have any questions, concerns or comments, then we shall be pleased to hear them. We are always aiming to
    improve our service, and so your feedback will be appreciated.
    <br />
    <br />
    Regards,
    <br />
    <br />
    The UK eScience CA Support Centre
</body>

</html>
2026-04-27T09:57:02.637+01:00 ERROR 423739 --- [iry-scheduler-1] uk.ac.ngs.service.email.EmailService     : MailSender Failed messages: org.eclipse.angus.mail.smtp.SMTPSendFailedException: 530-5.7.0 Must issue a STARTTLS command first. For more information, go to
530-5.7.0  https://support.google.com/a/answer/3221692 and review RFC 3207
530 5.7.0 specifications. 5b1f17b1804b1-488fb74c789sm233860095e9.5 - gsmtp

2026-04-27T09:57:02.642+01:00  INFO 423739 --- [iry-scheduler-1] uk.ac.ngs.service.CertificateService     : No certificates are going to expire after 30 days.
2026-04-27T09:57:02.643+01:00  INFO 423739 --- [iry-scheduler-1] uk.ac.ngs.TaskConfig                     : Completed daily certificate expiry reminder job successfully in 2448 ms

Sample email in html

image

@garaimanoj garaimanoj self-assigned this Apr 24, 2026
Comment thread src/main/java/uk/ac/ngs/dao/JdbcCertificateDao.java Fixed
Comment on lines +487 to +489
long endOfDay = Long.parseLong(
formatter.format(targetDate.plusDays(1)
.atStartOfDay(ZoneOffset.UTC)));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yyyyMMddHHmmss produces only digits → safe to parse as long

Comment on lines +485 to +486
long startOfDay = Long.parseLong(
formatter.format(targetDate.atStartOfDay(ZoneOffset.UTC)));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yyyyMMddHHmmss produces only digits → safe to parse as long

Comment thread src/main/java/uk/ac/ngs/service/email/EmailService.java Fixed
Comment thread src/main/java/uk/ac/ngs/service/email/EmailService.java Fixed
Comment thread src/main/java/uk/ac/ngs/service/email/EmailService.java Fixed
Comment thread src/main/java/uk/ac/ngs/service/email/EmailService.java Fixed
@garaimanoj garaimanoj requested a review from DonaldChung-HK May 13, 2026 07:37
@garaimanoj garaimanoj marked this pull request as ready for review May 13, 2026 07:37
Comment thread src/main/webapp/WEB-INF/freemarker/email/emailUserCertExpiryReminderTemplate.html Outdated
Comment thread src/main/webapp/WEB-INF/freemarker/email/emailUserCertExpiryReminderTemplate.html Outdated
garaimanoj and others added 2 commits May 13, 2026 16:32
…minderTemplate.html

Co-authored-by: rowan04 <rowanmoss04@gmail.com>
…minderTemplate.html

Co-authored-by: rowan04 <rowanmoss04@gmail.com>
@garaimanoj garaimanoj requested a review from rowan04 May 13, 2026 15:32
Copy link
Copy Markdown
Contributor

@DonaldChung-HK DonaldChung-HK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @garaimanoj, thanks for writing the feature, just a small bit of monitoring so that we can spot and diagnose issue of missing email more easily in the future (just being a bit cautious since it is possible that the issue is from the Postgres DB.)

certificateService.sendCertificateExpiryReminders();

long durationMs = System.currentTimeMillis() - startTime;
log.info("Completed daily certificate expiry reminder job successfully in {} ms",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a summary of number of SMTP mail pushed for 30 day and 7 day reminder as well so that we can spot the anomaly by comparing this number and expected number from DB. Thanks

Copy link
Copy Markdown
Contributor Author

@garaimanoj garaimanoj May 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done
Summary for 7-day expiry reminder (processingDate=2026-05-19): total=1, sent=0, failed=1

Comment on lines +516 to +520
try {
this.mailSender.send(msg, vars, this.emailUserCertExpiryReminderTemplate);
} catch (MailException ex) {
log.error("MailSender " + ex.getMessage());
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a log for CN (that can be toggled on/off) here for monitoring purposes so we know what did or did not get sent successfully to the SMTP server.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@garaimanoj garaimanoj requested a review from DonaldChung-HK May 19, 2026 14:39
Copy link
Copy Markdown
Contributor

@DonaldChung-HK DonaldChung-HK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the logging function. Looks good.

Copy link
Copy Markdown

@rowan04 rowan04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm after this small change!

Comment on lines +309 to +311
if(this.emailService.sendEmailReminderToUserOnCertExpiry(cert, daysToExpire)){
successCount++;
} else{
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(this.emailService.sendEmailReminderToUserOnCertExpiry(cert, daysToExpire)){
successCount++;
} else{
if (this.emailService.sendEmailReminderToUserOnCertExpiry(cert, daysToExpire)) {
successCount++;
} else {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good spot on the formatting.

@garaimanoj garaimanoj requested a review from rowan04 May 20, 2026 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants