邮箱注册

1 . 用到2个包 , 一个包对象SimpleMailMessage存储邮件信息 , 一个对象MailSender对象发送simplemailmessage

     javax.mail.jar

2 . 配置 , springmvc配置文件中

<!--邮件配置-->
    <bean id="simpleMailMessage" class="org.springframework.mail.SimpleMailMessage">
        <property name="from" value="[email protected]"/>
        <property name="subject" value="[XXXX项目]请您激活账户!"/>
    </bean>
    <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="smtp.163.com"/>
        <property name="port" value="25"/>
        <property name="username" value="[email protected]"/>
        <property name="password" value="*****"/>
        <property name="defaultEncoding" value="UTF-8"/>
    </bean>

3 . 实现类

@Service
public class MailServiceImpl implements MailService{
	@Resource
	private SimpleMailMessage simpleMailMessage;
	@Resource
	private MailSender mailSender;

	@Override
	public void sendMail(String mailTo, String activationCode) {
		simpleMailMessage.setTo(mailTo);
		simpleMailMessage.setText("请点击激活码 : http://192.168.1.99/auth/api/doactivate?mail="+mailTo+"&activationCode="+activationCode);
		mailSender.send(simpleMailMessage);
	}
}

猜你喜欢

转载自blog.csdn.net/qq_42237676/article/details/81144082