我想使用速度模板发送邮件。
我的配置基于Spring 3.1文档。
我有一个配置的xml文件:
<?xml version="1.0" encoding="UTF-8"?>
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd“>
<bean id="sendMail" class="com.myclass.app.SendMail">
<property name="mailSender" ref="mailSender"/>
<property name="velocityEngine" ref="velocityEngine"/>
</bean>
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="velocityProperties">
<value>
resource.loader=class
class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
</value>
</property>
</bean>
然后我上课:
@Controller
public class SendMail{
private static final Logger logger = Logger.getLogger(SendMail.class);
private JavaMailSender mailSender;
private VelocityEngine velocityEngine;
public void setMailSender(JavaMailSender mailSender) {
this.mailSender = mailSender;
}
public void setVelocityEngine(VelocityEngine velocityEngine) {
this.velocityEngine = velocityEngine;
}
@RequestMapping(value = "/sendEmail", method = RequestMethod.GET)
public @ResponseBody void send(){
sentEmail();
}
private void sentEmail(){
try {
// SimpleMailMessage msg = new SimpleMailMessage(mailMessage);
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message,
true, "UTF-8");
helper.setFrom("from@from.com");
helper.setTo("myEmail");
helper.setSubject("title");
Map map = new HashMap();
map.put("user", "Piotr");
map.put("test", "TEST");
String text1 = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, "velocity.vm", map );
logger.info(text1);
String text = "test";
helper.setText(text, true);
mailSender.send(message);
} catch (Exception ex) {
System.out.println(ex.getStackTrace());
System.out.println(ex.getMessage());
}
}
}
我的vm文件位于“资源”文件夹中。
而我所有收到的ID“零点异常”;
回应没有给我更多。
您有什么想法,怎么办?
您的模板不能在资源中,它们必须在您可以在applicationContext.xml的velocityEngine中配置的类路径中:
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="ADDRESS_OF_YOUR_SMTP_SERVER"/>
<property name="defaultEncoding" value="UTF-8"/>
<property name="port" value="XX_PORT_SERVER"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtps.auth">false</prop> <!-- depending on your smtp server -->
<prop key="mail.smtp.starttls.enable">false</prop>
</props>
</property>
</bean>
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean" p:resourceLoaderPath="classpath:META-INF/velocity" />
不要忘记名称空间xmlns:p =“ http://www.springframework.org/schema/p”来使用上面示例的属性。
在您的Java类SendMail中,不要忘记添加注释@Autowired:
@Autowired
public void setMailSender(JavaMailSender mailSender) {
this.mailSender = mailSender;
}
@Autowired
public void setVelocityEngine(VelocityEngine velocityEngine) {
this.velocityEngine = velocityEngine;
}
最后,使用MimeMessagePreparator发送您的电子邮件:
MimeMessagePreparator preparator = new MimeMessagePreparator() {
@Override
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
message.setTo("blabla@test.com");
message.setSubject("Email test");
String text = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, template, keywords);
message.setText(text, true);
}
};
//Send email using the autowired mailSender
this.mailSender.send(preparator);
速度传感器(图 1A 和 图 2A) 辐条感应磁铁(图 2 B) 图 1 图 2
Java容器总共分为几大类,有哪些容器 ArrayList和LinkedList的区别 List和Set的区别 HashSet和HashMap的区别和联系 HashSet不是用唯一的键来获取吗 HashSet和TreeSet的区别 Spring有两个特征,这两个特征是什么 Aop的实现原理 Ioc的思想是什么 线程池了解哪些?它的工作原理是什么 Redis了解吗?redis的类型有哪些 Redis
我创建了两个长列表,重复两个不同的值。在第一个列表中,值交替出现,在第二个列表中,一个值出现在另一个值之前: 然后我迭代它们,对它们不做任何操作: 两者哪个迭代更快?取决于我如何测量!我用每种计时方法跑了50场比赛: 为什么这两种计时方法给我的结果完全相反?为什么这两个列表之间存在速度差异?我希望有两次25-25,而不是50-0和0-50。 之前类似问题的原因以及我认为他们不应该对此负责的原因:
通过速度/步速区,您可以在训练课中轻松监控速度或步速,并调整速度/步速,以达到目标训练效果。这些区域可以用来指导您在训练课期间的训练效率,并帮助您组合与不同的训练强度,以获得最佳效果。 速度区设置 可以在 Flow 网络服务上调整速度区设置。有五个不同的速度区,您可手动调整速度限制,或使用默认区。速度区特定于运动,您可以加以调整,以最佳适合每项运动。这些区域可用于跑步运动(包括涉及跑步的团队运动)
通过速度/步速区,您可以在训练课中轻松监控速度或步速,并调整速度/步速,以达到目标训练效果。这些区域可以用来指导您在训练课期间的训练效率,并帮助您组合与不同的训练强度,以获得最佳效果。 速度区设置 可以在 Flow 网络服务上调整速度区设置。有五个不同的速度区,您可手动调整速度限制,或使用默认区。速度区特定于运动,您可以加以调整,以最佳适合每项运动。这些区域可用于跑步运动(包括涉及跑步的团队运动)
我试图理解快速排序机制,但到目前为止,我还不能弄清楚它。根据维基百科,步骤是: 1.从列表中选择一个元素,称为pivot。 这是代码: 除了一件事,对我来说一切都很清楚。为什么分区函数返回而不是?