Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SpringVelocity模板电子邮件?_Java_Spring_Email_Spring Mvc_Apache Velocity - Fatal编程技术网

Java SpringVelocity模板电子邮件?

Java SpringVelocity模板电子邮件?,java,spring,email,spring-mvc,apache-velocity,Java,Spring,Email,Spring Mvc,Apache Velocity,我有下面的速度模板 <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <style> table, th, td { border: 1px solid black; border-collapse: collapse; } th, td { padding

我有下面的速度模板

<!DOCTYPE html>
<html>
<head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">

<style>
table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
}
th, td {
    padding: 5px;
    text-align: left;
}
</style>
</head>
<body>

<h4>Dear User</h4><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Your Instance has been created Successfully.<br/>
Please find attached <b>.pem</b> file which is required to login to your machine.<br/>

<h2>Machine Details:</h2>

<table style="width:100%">
  <tr>
    <th>Public IP:</th>
    <td>${publicIP}</td>
  </tr>
  <tr>
    <th>Public DNS:</th>
    <td>${publicDns}</td>
  </tr>
  <tr>
    <th>User Name:</th>
    <td>${userName}</td>
  </tr>
</table>

</body>
</html>
<br/>
收到的邮件:
在上面的邮件中,为什么不使用值替换占位符?请帮帮我。

我忘了为对象中的那些字段设置值

public void sendMail(MailParams params) throws MessagingException {

        MimeMessage message = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
        helper.setFrom(params.getMailFrom());
        helper.setTo(params.getMailTo());
        helper.setSubject(params.getMailSubject());
        Template template = velocityEngine.getTemplate("./templates/"
                + params.getTemplateName());

        VelocityContext velocityContext = new VelocityContext();
        velocityContext.put("publicIP", params.getPublicIP());
        velocityContext.put("publicDns", params.getPublicDns());
        velocityContext.put("userName", params.getUserName());

        StringWriter stringWriter = new StringWriter();

        template.merge(velocityContext, stringWriter);

        //helper.setText(stringWriter.toString());
        message .setContent(stringWriter.toString(), "text/html");
        mailSender.send(message);
    }
Dear User

       Your Instance has been created Successfully.
Please find attached .pem file which is required to login to your machine.
Machine Details:
-----------------------------
|Public IP: |${publicIP}     |
|Public DNS:    |${publicDns}|
|User Name: |${userName}     |
-----------------------------