Class MailMBean
java.lang.Object
ecmwf.common.technical.ThreadService.ConfigurableRunnable
ecmwf.common.technical.WakeupThread
ecmwf.common.ecaccess.ECaccessScheduler
ecmwf.common.ecaccess.MBeanScheduler
ecmwf.common.ecaccess.MBeanRepository<ecmwf.common.ecaccess.MailMessage>
ecmwf.common.ecaccess.MailMBean
- All Implemented Interfaces:
MBeanService, MonitorCallback, Closeable, AutoCloseable, Runnable
Manages sending and receiving emails through SMTP/IMAP/POP protocols.
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the list of mail interfaces.getStatus(ecmwf.common.ecaccess.MailMessage message) Returns a string representation of the mail message status.voidInitializes the mail subsystem by configuring and creating a JavaMailSessionbased on the application's configuration.intnextStep()Executes the next step in the MBean workflow: connect, send, receive.voidSends an email without CC or attachment.voidsendMail(String from, String to, String cc, String subject, String content, String attachmentName, String attachmentContent) Sends an email with optional CC and attachment.voidshutdown()Shutdown.voidshutdown(boolean graceful) Shuts down the MBean and optionally sends pending messages.Methods inherited from class MBeanRepository
clear, containsKey, containsValue, getAttribute, getComparator, getKey, getList, getList, getMBeanInfo, getSize, getStatus, getValue, getWakeup, invoke, put, removeKey, removeValue, setComparator, setMaxAuthorisedSize, setWakeup, sortMethods inherited from class MBeanScheduler
close, getMonitorName, setAttributeMethods inherited from class ECaccessScheduler
configurableRun, deactivateMonitor, getActivity, getDelay, getJammedTimeout, getLastStepTime, getMonitorManager, getNextStep, getSchedulerState, getStartDate, getStepTime, isInitialized, isJammed, isOnHold, isRunning, onHold, setDelay, setJammedTimeout, setOnhold, setTimeRanges, start, wakeupMethods inherited from class WakeupThread
isSleeping, waitForMethods inherited from class ThreadService.ConfigurableRunnable
execute, execute, execute, getContextClassLoader, getPriority, getThreadName, interrupt, interrupted, isAlive, isStarted, join, join, run, setContextClassLoader, setForceCookie, setInheritCookie, setPriority, setThreadNameAndCookie
-
Constructor Details
-
MailMBean
Constructs a MailMBean with the specified name.- Parameters:
name- the MBean name
-
MailMBean
-
-
Method Details
-
getStatus
Returns a string representation of the mail message status.- Overrides:
getStatusin classMBeanRepository<ecmwf.common.ecaccess.MailMessage>- Parameters:
message- the mail message- Returns:
- the status string
-
getMailInterfaces
Returns the list of mail interfaces.- Returns:
- array of mail interfaces
-
sendMail
-
sendMail
public void sendMail(String from, String to, String cc, String subject, String content, String attachmentName, String attachmentContent) Sends an email with optional CC and attachment.- Parameters:
from- the senderto- the recipient(s)cc- the CC recipient(s)subject- the subjectcontent- the message contentattachmentName- the attachment nameattachmentContent- the attachment content
-
initialize
public void initialize()Initializes the mail subsystem by configuring and creating a JavaMailSessionbased on the application's configuration.This method sets up:
- SMTP (sending) — always enabled and configured using the "Mail.smtpHost", "Mail.port", "Mail.auth", and "Mail.starttls" settings.
- Mail store (receiving) — optionally enabled when both "Mail.storeHost" and "Mail.storeType" are
provided. Supported store protocols include
imap,imaps,pop3, andpop3s.
All SSL/TLS settings for both SMTP and the mail store are applied using the corresponding configuration keys. A dedicated
Authenticatoris installed to supply credentials for both sending and receiving actions.This method is thread‑safe and will initialize the session only once.
Configuration keys used:
- Mail.smtpHost – SMTP server hostname
- Mail.port – SMTP port
- Mail.auth – Enable SMTP authentication
- Mail.starttls – Enable SMTP STARTTLS
- Mail.storeHost – IMAP/POP server hostname (optional)
- Mail.storeType – One of: imap, imaps, pop3, pop3s (optional)
- Mail.storePort – Store port (optional, defaults per protocol)
- Mail.user – Username for both SMTP and store
- Mail.password – Password for authentication
- Mail.folderName – Folder to open when using a store (default: INBOX)
- Mail.debug – Enable JavaMail debug output
Thread-safety
The method is synchronized and will skip initialization if a session already exists, ensuring that the mail system is configured exactly once.Logging
A summary of the effective configuration is logged, with credentials safely masked.- Overrides:
initializein classECaccessScheduler
-
nextStep
public int nextStep()Executes the next step in the MBean workflow: connect, send, receive.- Specified by:
nextStepin classECaccessScheduler- Returns:
- delay until next step
-
shutdown
public void shutdown(boolean graceful) Shuts down the MBean and optionally sends pending messages.- Parameters:
graceful- if true, send pending messages before shutdown
-
shutdown
-