当前位置: 首页 > news >正文

sns社交网站源码网站建设知识点有哪些漏缺

sns社交网站源码,网站建设知识点有哪些漏缺,如何建设网站pdf,个人网站注册流程在上一篇Spring电子邮件教程,硬编码的所有电子邮件属性和消息的方法体中的内容,这是不实际的,应予以避免。应该考虑在Spring bean 配置文件中定义电子邮件模板。1.Spring的邮件发件人Java类使用 Spring的MailSender接口发送电子邮件&#xff…
在上一篇Spring电子邮件教程,硬编码的所有电子邮件属性和消息的方法体中的内容,这是不实际的,应予以避免。应该考虑在Spring bean 配置文件中定义电子邮件模板。
1.Spring的邮件发件人
Java类使用 Spring的MailSender接口发送电子邮件,并使用 String.Format 传递变量bean配置文件替换电子邮件中的 '%s'。

File : MailMail.java

package com.yiibai.common;import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;public class MailMail
{private MailSender mailSender;private SimpleMailMessage simpleMailMessage;public void setSimpleMailMessage(SimpleMailMessage simpleMailMessage) {this.simpleMailMessage = simpleMailMessage;}public void setMailSender(MailSender mailSender) {this.mailSender = mailSender;}public void sendMail(String dear, String content) {SimpleMailMessage message = new SimpleMailMessage(simpleMailMessage);message.setText(String.format(simpleMailMessage.getText(), dear, content));mailSender.send(message);}	
}

2. Bean的配置文件

定义电子邮件模板“customeMailMessage' 和邮件发件人信息的bean配置文件。

File : Spring-Mail.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"><bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"><property name="host" value="smtp.gmail.com" /><property name="port" value="587" /><property name="username" value="username" /><property name="password" value="password" /><property name="javaMailProperties"><props><prop key="mail.smtp.auth">true</prop><prop key="mail.smtp.starttls.enable">true</prop></props></property>
</bean><bean id="mailMail" class="com.yiibai.common.MailMail"><property name="mailSender" ref="mailSender" /><property name="simpleMailMessage" ref="customeMailMessage" />
</bean><bean id="customeMailMessage"class="org.springframework.mail.SimpleMailMessage"><property name="from" value="from@no-spam.com" /><property name="to" value="to@no-spam.com" /><property name="subject" value="Testing Subject" /><property name="text"><value><![CDATA[Dear %s,Mail Content : %s]]></value></property>
</bean></beans>

4. 运行它

package com.yiibai.common;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class App 
{public static void main( String[] args ){ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");MailMail mm = (MailMail) context.getBean("mailMail");mm.sendMail("Yiibai", "This is text content");}
}

输出

Dear Yiibai,Mail Content : This is text content
代码下载 –  http://pan.baidu.com/s/1c0UPsFA

转载于:https://www.cnblogs.com/soundcode/p/6367590.html

http://www.yutouwan.com/news/624/

相关文章:

  • 苏州网站建立公司wordpress xiu5.4
  • 开源程序做网站任务网站跟别的做的一样的
  • 网站优化网湛江做网站需要什么
  • 给做网站公司写锦旗语舟山网站制作
  • 网站建设行业知乎郑州制作平台网站
  • 多终端网站开发网站代码建设 实例
  • 网站开发精品课程网络推广技巧与方法
  • 免费发布产品网站网站备案更换主体
  • 网站开发资讯北京住房城乡建设网站
  • 如何 建公司网站网络推广合作资源平台
  • 国内便宜机票网站建设wordpress 自定义文章
  • asp网站和php网站c 网站开发用的人多吗
  • 为什么做网站必须要用域名做啊网站
  • 开网站做淘宝客中秋网页设计素材网站
  • 怎么做黑客把网站余额更改北京计算机培训机构哪个最好
  • 学院门户网站建设自评大连网站建设外包公司
  • 仿牌网站建设双峰做网站
  • 移动网站开发技术有哪些怎么做网站快照
  • 网站建设地带网站建设课程设计报告
  • 广州专业的做网站公司张家界seo服务
  • 湖北强涛建设工程有限公司网站网站维护与排名
  • 只使用html做简单网站百度seo排名优化是什么
  • wordpress贴心插件seo投放
  • wordpress 中介网站松江新城做网站
  • 网站两侧广告代码四川住建厅官方网站的网址
  • 做网站毕业答辩会问什么企业网站建设设计方案
  • 延安市建设局网站六种常见的网站类型
  • 浏览器打开自己做的网站做微信推送封面的网站
  • 网站加alt属性对优化有影响吗自己做的网站安全吗
  • 网站运营和推广ui页面设计公司