Quick revision
The short answer
First we contain the damage: rotate the leaked credentials at once, check which other services share them, and review SPF, DKIM and DMARC so that mail not sent through our approved path is rejected rather than delivered in our name. Then we fix the cause: centralise sending in one notification service that holds the provider credentials, enforces rate limits and audits every message, with other services calling it through an API or events. Credentials live in a secret manager scoped per sender, volume is monitored for anomalies, templates and consent handling are standardised, and services migrate over a defined period, after which SMTP access is removed from application networks.
What to remember
In this answer, we contained the leak by rotating credentials and finding the leak path, used SPF, DKIM and DMARC to limit who can send as our domain, centralised sending in a notification service with audit and rate limits, scoped credentials in a secret manager with volume alerts, standardised templates and consent, and finished by migrating services and removing SMTP access from application networks.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
First we contain the damage: rotate the leaked credentials at once, check which other services share them, and review SPF, DKIM and DMARC so that mail not sent through our approved path is rejected rather than delivered in our name. Then we fix the cause: centralise sending in one notification service that holds the provider credentials, enforces rate limits and audits every message, with other services calling it through an API or events. Credentials live in a secret manager scoped per sender, volume is monitored for anomalies, templates and consent handling are standardised, and services migrate over a defined period, after which SMTP access is removed from application networks.
Why this question is asked
A leaked SMTP password is an incident with a long tail. The spam may stop as soon as we rotate the password, but our domain's reputation with mail providers can take weeks to recover, and until then real order confirmations land in spam folders. The leak was also not bad luck: with credentials copied into many services, the chance that one of them ends up in a log, a repository or a misconfigured container grows with every copy. Interviewers ask this leadership question to see whether we can respond to the incident and then remove the structure that made it likely. In this answer, we will go through the immediate response, the email authentication settings that limit abuse, the centralised design, credential and volume controls, standards for templates and consent, and how to run the migration.
1Contain the Incident First
The first hour is about stopping the abuse. We rotate the leaked credential with the provider, and because many services had their own configuration, we check whether the same credential was reused elsewhere, which is common when people copy a working configuration. We look at the provider's logs to see how many messages were sent, to whom and from which source addresses, and we ask the provider to block the old credential and to tell us whether our account was flagged.
Then we find how it leaked, for example a password committed to a repository, printed in a startup log, or baked into a container image, so the same path cannot leak the new credential. This is also the moment to tell the people who need to know: security, support (customers may report phishing in our name) and whoever owns the domain.
2SPF, DKIM and DMARC: Limiting Abuse of the Domain
Three DNS-based standards decide whether mail claiming to be from our domain is trusted. SPF lists which servers may send mail for the domain. DKIM adds a cryptographic signature to each message, which the receiver checks against a public key in our DNS. DMARC tells receivers what to do when a message fails those checks, and asks them to send us reports.
They do not stop someone who has valid credentials for our real provider, since that mail passes SPF and DKIM. What they do is shrink the set of paths that count as valid. If DMARC is at p=none, anyone can spoof our domain from anywhere and receivers still deliver it; moving to p=quarantine and then p=reject, with SPF listing only the notification service's provider, means only that one path can deliver mail in our name.
Notice -all in SPF, a hard fail for unlisted senders, and p=reject in DMARC. With many services sending through different SMTP servers, a strict policy like this was impossible, because one forgotten sender would have its real mail rejected. Centralising sending is what makes the strict policy safe.
3Centralise Sending in a Notification Service
The structural fix is one notification service that owns all email. It holds the only provider credentials, renders templates, applies rate limits per calling service and per recipient, and writes an audit record for every message: who asked, which template, which recipient, when, and the provider's result. Other services no longer configure JavaMailSender at all. They send a request, either through an API call or by publishing an event such as SendEmailRequested.
- Product servicespublish
SendEmailRequestedor call the notification API - Notification servicetemplates, consent, rate limits, audit, retries
- Secret managerthe only provider credential, rotated on schedule
- Email providerSPF and DKIM aligned for
example.com - DNS policyDMARC p=reject for any other path
5 layers, from the top down. Step through them one at a time.
4Credentials, Scoping and Volume Monitoring
The notification service reads its credential from a secret manager, never from a properties file or an environment variable baked into an image, and the credential is rotated on a schedule. If the provider supports it, we create separate credentials or API keys per sending purpose, for example transactional and marketing, each limited to its own sender addresses, so a leak of one cannot send as the other and can be revoked alone.
Volume monitoring would have caught this leak early. A normal day might be 40,000 messages; a sudden 300,000 in an hour, a jump in bounces, or mail to recipients we have never contacted is an anomaly. The notification service and the provider both expose these numbers, and an alert on volume per hour against a baseline, plus provider-side sending caps, turns a day-long spam run into a ten-minute one.
5Standardise Templates, Unsubscribe and Consent
Centralising also lets us fix what every team was doing slightly differently. Templates live in one place, are versioned and reviewed, and share a layout and footer. Marketing-type messages carry a working unsubscribe link and, for bulk senders, the List-Unsubscribe header that large mailbox providers now expect. Consent is checked in one place before sending, so a customer who opted out is respected by every product, which also matters for privacy regulation in many countries.
6Running the Migration
A central service only helps once services actually use it. We announce a defined period, for example one quarter, publish a client library or event schema that makes switching a small change, and migrate the highest-volume and highest-risk senders first. Progress is a visible number: services still holding SMTP credentials.
When the last service has moved, we revoke all old credentials and remove outbound SMTP access, ports 25, 465 and 587, from application networks with firewall or network policy rules, allowing it only from the notification service. That last step turns the standard into a guarantee: even a future team that copies an old configuration cannot send mail directly.
- Rotate and investigatehours: stop the abuse, find the leak
- Tighten SPF, DKIM, DMARCmove toward p=reject
- Build notification servicecredentials, limits, audit, templates
- Migrate servicesone quarter, highest risk first
- Remove SMTP egressonly the notification service may send
5 steps in order. Play them, or step through them one at a time.
7Follow-up questions
Does a central notification service create a single point of failure?
It concentrates risk, so it must be built for it: several instances, a durable queue in front so callers are not blocked when it is slow, and a fallback provider for critical transactional mail. In exchange, one well-run service is far more reliable than 40 copies of mail configuration that nobody watches.
How do you protect the domain's reputation after the spam run?
Stop the abuse, then send only clean, wanted mail, ideally from a subdomain for marketing so transactional reputation is separate. DMARC reports show whether anything else is still sending as us, and the provider can tell us whether our sending IPs are on blocklists.
Why not just put the credentials in a secret manager and keep sending per service?
It reduces one leak path, but 40 copies of a powerful credential remain, each with its own access policy, and there is still no central place to rate limit, audit or enforce consent. The secret manager is necessary but not sufficient.
8Conclusion
In this answer, we contained the leak by rotating credentials and finding the leak path, used SPF, DKIM and DMARC to limit who can send as our domain, centralised sending in a notification service with audit and rate limits, scoped credentials in a secret manager with volume alerts, standardised templates and consent, and finished by migrating services and removing SMTP access from application networks.
Open with
First I'd contain it: rotate the leaked credential immediately, check whether other services reused the same one, read the provider's logs to see the scale, and find how it leaked, a repository, a log or an image, so the new credential doesn't leak the same way.
Then, if they want more
At the same time I'd review SPF, DKIM and DMARC. They won't stop someone with our real credentials, but moving DMARC towards p=reject with a strict SPF list means only our approved path can deliver mail in our name. Then I'd fix the cause, which is that 40 services each hold powerful credentials.
I'd centralise sending in a notification service that owns the only provider credentials, renders versioned templates, checks consent and unsubscribes, rate limits per caller and recipient, and audits every message. Other services call it through an API or publish an event.
Its credentials live in a secret manager, scoped per purpose where the provider allows it, and rotated on a schedule. I'd add volume and bounce alerts against a baseline, because that would have turned this incident from a day into minutes.
Finally, I'd run the migration over a defined period, highest-risk senders first, track how many services still hold SMTP credentials, and when it reaches zero, revoke the old credentials and block SMTP ports from application networks so direct sending is no longer possible.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Core technologies
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Many Spring Boot services each send email with their own JavaMailSender configuration...": https://scrivio-interview-library.netlify.app/spring-boot/spring-utilities/0f30daec36/