通过从数据库获取邮件结构在JAVA中发送邮件

问题描述 投票:0回答:1

我必须使用Java在ADF中发送邮件,但是邮件结构来自数据库,但是我不知道如何使用该结构并将动态值分配给它。以下是结构:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <html>
            <head>
                <title>Email Notification</title>
                <style type="text/css"> body.font-type { font-family: Arial, Helvetica, sans-serif; } div.main-border { border: 1px solid black; width: 100%; } table { width: 100%; border: 1px solid black; } th.main-header { font-size: 18px; font-weight: bold; background-color: rgb(57, 73, 94); text-align: center; color: white; border: 1px solid black; } th.sub-header { font-size: 14px; font-weight: bold; background-color: rgb(189, 215, 238); text-align: center; border: 1px solid black; } th.sub-header-h { font-size: 14px; font-weight: bold; background-color: rgb(189, 215, 238); text-align: right; border: 1px solid black; width: 29%; } table, th, td { border-collapse: collapse; } td { border: 1px solid black; text-align: center; } td.content { text-align: center; }button{background-image:none;border-bottom-left-radius:3px;border-bottom-right-radius:3px;border-bottom-style:solid;border-bottom-width:1px;border-image-outset:0;border-image-repeat:stretch;border-image-slice:100%;border-image-source:none;border-image-width:1;border-left-style:solid;border-left-width:1px;border-right-style:solid;border-right-width:1px;border-top-left-radius:3px;border-top-right-radius:3px;border-top-style:solid;border-top-width:1px;box-sizing:border-box;cursor:pointer;display:block;float:left;font-family:"Helvetica Neue",Roboto,Arial,"Droid Sans",sans-serif;font-feature-settings:normal;font-kerning:auto;font-language-override:normal;font-optical-sizing:auto;font-size:14px;font-size-adjust:none;font-stretch:100%;font-style:normal;font-variant:normal;font-variant-alternates:normal;font-variant-caps:normal;font-variant-east-asian:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-position:normal;font-variation-settings:normal;font-weight:400;line-height:20px;min-height:1px;overflow:visible;overflow-x:visible;overflow-y:visible;padding-bottom:6px;padding-left:10px;padding-right:10px;padding-top:6px;text-align:center;text-decoration:none;text-decoration-color:#fff;text-decoration-line:none;text-decoration-style:solid;text-transform:none;white-space:nowrap;width:175.5px;-moz-appearance:button;-moz-user-select:none}button.approve{background-color:#2e6da4;border-bottom-color:#204d74;border-left-color:#204d74;border-right-color:#204d74;border-top-color:#204d74;color:#fff}button.reject{background-color:red;border-bottom-color:red;border-left-color:red;border-right-color:red;border-top-color:red;color:#fff}</style>
            </head>
            <table>
<tbody>
<tr>
<th class="main-header">LC Details</th>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<th class="sub-header-h">LC Number</th>
<td class="content">&nbsp;</td>
</tr>
<tr>
<th class="sub-header-h">Facility Number</th>
<td class="content">&nbsp;</td>
</tr>
<tr>
<th class="sub-header-h">LC Amount Created</th>
<td class="content">&nbsp;</td>
</tr>
<tr>
<th class="sub-header-h">Expiry Date</th>
<td class="content">&nbsp;</td>
</tr>
<tr>
<th class="sub-header-h">Project number</th>
<td class="content">&nbsp;</td>
</tr>
<tr>
<th class="sub-header-h">Cost Center</th>
<td class="content">&nbsp;</td>
</tr>
<tr>
<th class="sub-header-h">Bank Account</th>
<td class="content">&nbsp;</td>
</tr>
</tbody>
</table>
        </html>
    </xsl:template>
</xsl:stylesheet>

This image is output of the structure

下面是我发送邮件的班级>>


import java.time.LocalDate;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

public class Mail {
    public static void main(String[] args) {

        String host = "smtp.gmail.com";
        final String user = "test.";// change accordingly
        final String password = "Wel";// change accordingly

        String to = "[email protected]";// change accordingly
        StringBuilder msg = new StringBuilder();

        // Get the session object
        Properties props = new Properties();
        props.put("mail.smtp.host", host);
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "587");

        Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(user, password);
            }
        });

        // Compose the message
        try {
            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress(user));
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
            message.setSubject("Dummy Email");
            message.setContent(text, "text/html");

            // send the message
            Transport.send(message);

            System.out.println("message sent successfully...");

        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }
}

请告诉我如何在运行时通过使用JAVA从数据库获取该结构来为空文本框设置值

我必须使用Java在ADF中发送邮件,但是邮件结构来自数据库,但是我不知道如何使用该结构并将动态值分配给它。以下是结构:&...

java javamail oracle-adf
1个回答
0
投票
getDataFromDataBase() {

        logger.info("---Début: récupération de données depuis la BD ---");
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            WriteTxtFile.setExitCode(1);
            logger.error("Oracle Driver Class Not found Exception: ",e.toString());
            return null;
        }
        DriverManager.setLoginTimeout(60);

        try {
            String url = url of your database;
            conn = DriverManager.getConnection(url, user,
                    password);
        } catch (SQLException e) {

            return null;
        }

        // Creates a Statement object for sending SQL statements to the database
        try {
            statement = conn.createStatement();
            String sql = your query;

            rs = statement.executeQuery(sql);
            String content="";
            while (rs.next()) {
                content=content+rs.getString("your column name"),
                content=content+rs.getString("your column name2"),
            }

            statement.close();
        } catch (SQLException e) {
            logger.error(e.toString());
        }
        logger.info("---Fin: récupération de données depuis la BD ---");
        return lines;
    }
© www.soinside.com 2019 - 2024. All rights reserved.