spring mail velocity

来源:互联网 发布:田原1968淘宝网 编辑:程序博客网 时间:2024/06/08 10:06

使用spring email 发邮件的列子横多

可看http://blog.csdn.net/xuelianjiale88/article/details/9145551

这里主要讲邮件模板的相关配置

注:velocity为classpath中存放模板的文件夹

maven项目直接放在src/main/resource下

velocity中存在的email模板text.vm

text.vm内容如下:

你好!${me}这是模板生成的邮件。


  Velocity配置文件详解 
在velocity的发布方包中有一个velocity.properties 
(位于 org.apache.velocity.runtime.defaults package下,文件定义了velocity的配置信息org.apache.velocity.runtime.RuntimeConstants中定义了key值) #模板编码: 
input.encoding=ISO-8859-1//模板输入编码 output.encoding=ISO-8859-1 //模板输出编码 #foreach配置 
directive.foreach.counter.name= velocityCount //计数器名称 directive.foreach.counter.initial.value = 1 //计数器初始值 directive.foreach.maxloops = -1 //最大循环次数,-1为默认不限制 directive.foreach.iterator.name = velocityHasNex //迭代器名称 #set配置 
directive.set.null.allowed = false //是否可设置空值 #include配置 
directive.include.output.errormsg.start= <!-- include error : //错误信息提示开始字符串 
directive.include.output.errormsg.end = see error log --> //错误信息提示结束字符串 #parse配置 
directive.parse.max.depth = 10 //解析深度 #模板加载器配置 
resource.loader = file //模板加载器类型,默认为文件,可定义多个 
file.resource.loader.description= Velocity File Resource Loader //加载器描述 file.resource.loader.class 
=Velocity.Runtime.Resource.Loader.FileResourceLoader //加载器类名称 file.resource.loader.path = . //模板路径 
file.resource.loader.cache = false //是否启用模板缓存 
file.resource.loader.modificationCheckInterval = 2 //检查模板更改时间间隔 宏配置 
velocimacro.library//指定宏定义文件的位置 
velocimacro.permissions.allow.inline= true //是否可以行内定义 
velocimacro.permissions.allow.inline.to.replace.global = false //是否可以用行内定义代替全局定义 
velocimacro.permissions.allow.inline.local.scope = false //行内定义是否只用于局部 
velocimacro.context.localscope= false //宏上下文是否只用于局部 velocimacro.max.depth = 20 //解析深度 
velocimacro.arguments.strict= false //宏参数是否启用严格模式 #资源管理器配置 
resource.manager.class= Velocity.Runtime.Resource.ResourceManagerImpl //管理器类名称 
resource.manager.cache.class = Velocity.Runtime.Resource.ResourceCacheImpl //缓存器类名称 #解析器池配置 
parser.pool.class= Velocity.Runtime.ParserPoolImpl //解析池类名称 parser.pool.size = 40 //初始大小 #evaluate配置 
directive.evaluate.context.class= Velocity.VelocityContext //上下问类名称 #可插入introspector配置 
runtime.introspector.uberspect = Velocity.Util.Introspection.UberspectImpl //默认introspector类名称 

,这里主要整理 邮件的配置与相关方法

<!-- velocity引擎配置 -->
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
   <property name="velocityProperties">
       <props>

   配置模板加载器类型:
           <prop key="resource.loader">file</prop>

  配置加载器类:
           <prop key="file.resource.loader.class">org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader</prop>

         配置是否启用模板缓存:
           <prop key="file.resource.loader.cache">false</prop>

  配置检查模板更改时间间隔:
           <prop key="file.resource.loader.modificationCheckInterval">3</prop>

          定义模板的输入和输出模板编码的配置是:
           <prop key="input.encoding">UTF-8</prop>
           <prop key="output.encoding">UTF-8</prop>
       </props>
   </property>
</bean>

    

0 0