src/main/java/edu/kit/informatik/pcc/webinterface/mailservice/MailService.java
/**
     * The method to send an email. It gets the SMTP properties from mail properties file.
     *
     * @param from    from mail
     * @param to      to mail
     * @param subject subject line
     * @param text    mail body
     * @throws EmailException
     * @throws IOException
     */
The method to send an email. It gets the SMTP properties from mail properties file.
The method to send an email . It gets the SMTP properties from mail properties file .
public static void send(String from, String to, String subject, String text)
            throws EmailException, IOException {
        Objects.requireNonNull(from);
        Objects.requireNonNull(to);
        Properties properties = new Properties();
        properties.load(MailService.class.getResourceAsStream("/mail.properties"));
        String host = properties.getProperty("mail.smtp.host");
        String port = properties.getProperty("mail.smtp.port");
        String ssl = properties.getProperty("mail.smtp.ssl.enable");
        String username = properties.getProperty("mail.smtp.username");
        String password = properties.getProperty("mail.smtp.password");
        HtmlEmail email = new HtmlEmail();
        email.setHostName(host);
        email.setSmtpPort(Integer.parseInt(port));
        email.setAuthentication(username, password);
        email.setSSLOnConnect(Boolean.parseBoolean(ssl));
        email.setFrom(from);
        email.addTo(to);
        email.setSubject(subject);
        email.setHtmlMsg(text);
        email.send();
    }
public static void send ( String from , String to , String subject , String text ) throws EmailException , IOException { Objects . requireNonNull ( from ) ; Objects . requireNonNull ( to ) ; Properties properties = new Properties ( ) ; properties . load ( MailService . class . getResourceAsStream ( "/mail.properties" ) ) ; String host = properties . getProperty ( "mail.smtp.host" ) ; String port = properties . getProperty ( "mail.smtp.port" ) ; String ssl = properties . getProperty ( "mail.smtp.ssl.enable" ) ; String username = properties . getProperty ( "mail.smtp.username" ) ; String password = properties . getProperty ( "mail.smtp.password" ) ; HtmlEmail email = new HtmlEmail ( ) ; email . setHostName ( host ) ; email . setSmtpPort ( Integer . parseInt ( port ) ) ; email . setAuthentication ( username , password ) ; email . setSSLOnConnect ( Boolean . parseBoolean ( ssl ) ) ; email . setFrom ( from ) ; email . addTo ( to ) ; email . setSubject ( subject ) ; email . setHtmlMsg ( text ) ; email . send ( ) ; }
The method to send an email.
The method to send an email .
// check for null references // load email configuration from properties file // create an email message with html support // configure SMTP connection // set its properties accordingly // send it!