spring 发送电子邮件
首先应导入的jar包:mail(javax.mail)、activation(javax.activation)和spring-context-support。(此处不是spring jar)。
之后就是在spring的配置文件中添加发送电子邮件的相关配置信息
<!-- 发送注册邮件 --> <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> <property name="host" value="smtp.163.com" /> <property name="username" value="yotionking" /> <property name="password" value="xxxxxxxxxx" /> <property name="defaultEncoding" value="UTF-8" /> </bean>
最后就是具体的业务代码
SimpleMailMessage message = new SimpleMailMessage(); message.setFrom("[email protected]"); message.setSubject("Hi,this is spring mail,just for test!"); message.setTo(userInfo.getEmail()); message.setText("just for test "); mailSender.send(message);
相关推荐
yupi0 2020-10-10
spring 2020-08-18
编程点滴 2020-07-29
幸运小侯子 2020-07-05
itjavashuai 2020-07-04
qingjiuquan 2020-06-29
shushan 2020-06-25
小鱿鱼 2020-06-22
咻pur慢 2020-06-18
melonjj 2020-06-17
qingjiuquan 2020-06-13
neweastsun 2020-06-05
小鱿鱼 2020-06-05
mxcsdn 2020-05-31
吾日五省我身 2020-05-27
牧场SZShepherd 2020-05-27
sweetgirl0 2020-05-14