Class MailMBean

All Implemented Interfaces:
MBeanService, MonitorCallback, Closeable, AutoCloseable, Runnable

public class MailMBean extends MBeanRepository<ecmwf.common.ecaccess.MailMessage>
Manages sending and receiving emails through SMTP/IMAP/POP protocols.
  • Constructor Details

    • MailMBean

      public MailMBean(String name)
      Constructs a MailMBean with the specified name.
      Parameters:
      name - the MBean name
    • MailMBean

      public MailMBean(String group, String name)
      Constructs a MailMBean with the specified group and name.
      Parameters:
      group - the MBean group
      name - the MBean name
  • Method Details

    • getStatus

      public String getStatus(ecmwf.common.ecaccess.MailMessage message)
      Returns a string representation of the mail message status.
      Overrides:
      getStatus in class MBeanRepository<ecmwf.common.ecaccess.MailMessage>
      Parameters:
      message - the mail message
      Returns:
      the status string
    • getMailInterfaces

      public MailInterface[] getMailInterfaces()
      Returns the list of mail interfaces.
      Returns:
      array of mail interfaces
    • sendMail

      public void sendMail(String from, String to, String subject, String content)
      Sends an email without CC or attachment.
      Parameters:
      from - the sender
      to - the recipient(s)
      subject - the subject
      content - the message content
    • 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 sender
      to - the recipient(s)
      cc - the CC recipient(s)
      subject - the subject
      content - the message content
      attachmentName - the attachment name
      attachmentContent - the attachment content
    • initialize

      public void initialize()
      Initializes the mail subsystem by configuring and creating a JavaMail Session based 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, and pop3s.
      If no valid store configuration is present, the system operates in send‑only mode, and no IMAP/POP connection will be attempted.

      All SSL/TLS settings for both SMTP and the mail store are applied using the corresponding configuration keys. A dedicated Authenticator is 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:
      initialize in class ECaccessScheduler
    • nextStep

      public int nextStep()
      Executes the next step in the MBean workflow: connect, send, receive.
      Specified by:
      nextStep in class ECaccessScheduler
      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

      public void shutdown()
      Shutdown.
      Overrides:
      shutdown in class MBeanScheduler