我正在尝试使用thymeleaf模板发送电子邮件。但我收到一条错误消息
org.thymeleaf.exceptions.TemplateProcessingException: Resource resolution by ServletContext with org.thymeleaf.resourceresolver.ServletContextResourceResolver can only be performed when context implements org.thymeleaf.context.IWebContext [current context: org.thymeleaf.context.Context]
at org.thymeleaf.resourceresolver.ServletContextResourceResolver.getResourceAsStream(ServletContextResourceResolver.java:74)
at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:221)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1192)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1148)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1095)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1008)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:982)
at in.coep.vlabteam.leap.implementations.ScheduleNotificationImpl.sendNotification(ScheduleNotificationImpl.java:205)
at in.coep.vlabteam.leap.implementations.ScheduleNotificationImpl.sendScheduleNotificationMail(ScheduleNotificationImpl.java:105)
at in.coep.vlabteam.leap.services.ScheduleNotificationService.sendScheduleNotificationByMail(ScheduleNotificationService.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:64)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
10936 [taskScheduler-1] ERROR org.thymeleaf.TemplateEngine - [THYMELEAF][taskScheduler-1] Exception processing template "scheduleMail.html": Resource resolution by ServletContext with org.thymeleaf.resourceresolver.ServletContextResourceResolver can only be performed when context implements org.thymeleaf.context.IWebContext [current context: org.thymeleaf.context.Context]
我不能使用WebContext()而不是Context()。因为对于webContext,我需要我无法在这里获得的HttpServletRequest对象,因为它不在请求范围内。我正在尝试使用上下文()发送邮件,但我收到了错误。请任何人对此有解决方案。提前感谢这是我的代码,
final Context ctx = new Context();
ctx.setVariable("eagletId", user.getEagletId());
ctx.setVariable("name", user.getFirstName());
ctx.setVariable("setSentDate", new Date());
ctx.setVariable("department", user.getDepartment());
ctx.setVariable("batch", user.getBatch());
// ctx.setVariable("month" Constants.LeapConstants.UserType);
// Prepare message using a Spring helper
final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
final MimeMessageHelper message =
new MimeMessageHelper(mimeMessage, true /* multipart */, "UTF-8");
message.setSubject("Create your report for month");
message.setFrom("leap@gmail.com");
message.setTo("vlab@gmail.com");
// Create the HTML body using Thymeleaf
final String htmlContent = this.templateEngine.process("scheduleMail.html", ctx);
message.setText(htmlContent, true /* isHtml */);
// Send mail
this.mailSender.send(mimeMessage);
模板引擎配置为ServletContextTemplateResolver,而不是FileTemplateResolver或ClassLoaderTemplateResolver。这很可能是在spring配置文件的某个地方定义的。如果在代码中配置,请参阅关于配置模板引擎和templateResolver配置的Thymeleaf用户指南。这是好医生。
通过xml配置,它应该如下所示:
<beans:bean id="templateResolver"
class="org.thymeleaf.templateresolver.ClassLoaderTemplateResolver">
</beans:bean>
本文向大家介绍python3使用QQ邮箱发送邮件,包括了python3使用QQ邮箱发送邮件的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了python3使用QQ邮箱发邮件的具体代码,供大家参考,具体内容如下 直接上代码 如果登录失败可能是你的qq邮箱没有启动SMTP 解决: 启动后QQ会提供授权码,将代码中密码改为授权码即可。 成功后: 以上就是本文的全部内容,希望对大家的学习有所帮
我下载了Office 365 Connect ASP。NET MVC示例代码http://dev.office.com/code-samples-detail/5985,将其注册为Azure Active Directory中的应用程序(我具有全局管理员权限),并授予其所需的权限-“登录并读取用户配置文件”和“以用户身份发送邮件”(无其他权限),以及配置了web。配置为“ClientID”和“Cl
我试图从域发送邮件,但得到一些错误。
尽管Python 通过smtplib 模块使得发送邮件很简单,Django 仍然在此基础上提供了几个轻量的封装包。这些封装包使得发送邮件非常快速、让开发中测试发送邮件变得很简单、并且支持不使用SMTP 的平台。 这些代码包含在django.core.mail模块中。 简单例子 两行代码实现: from django.core.mail import send_mail send_mail('Su
cmf_send_email($address, $subject, $message) 功能 发送邮件 参数 $address: string 收件人邮箱 $subject: string 邮件标题 $message: string 邮件内容 返回 array 格式 array( "error"=>0|1,//0代表出错 "message"=> "出错信息" );
X1.0新增 sp_send_email($address,$subject,$message) 功能: 发送邮件 参数: $address:收件人地址 $subject:邮件主题 $message:邮件内容 返回: 类型数组,发送状态和信息 array( "error"=>"1",//有错误 "message"=>""错误信息 ); array( "error"=>"0