我有低于速度模板。
<!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/>
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} |
-----------------------------
在上述邮件中,为什么占位符不会被值替换?请帮帮我。
答案 0 :(得分:-1)
我忘了为对象中的那些字段设置值。