spring xml 配置 <!-- email --> <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> <property name="host" value="smtp.exmail.qq.com" /> <property name="port" value="465" /> <property name="username" value="xxxxxxx" /> <property name="password" value="xxxx" /> <property name="javaMailProperties"> <props> <prop key="mail.debug">true</prop> <prop key="mail.transport.protocol">smtp</prop> <prop key="mail.smtp.auth">true</prop> <prop key="mail.smtp.starttls.enable">true</prop> <prop key="mail.smtp.ssl.enable">true</prop> <!-- 是否启动ssl--> <prop key="mail.from">xxxxx</prop> </props> </property> </bean> controller 部分代码 ///验证是否是邮箱 if(phoneNum.matches("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*")){ SimpleMailMessage mailMessage=new SimpleMailMessage(); mailMessage.setTo(phoneNum); //接受邮箱 mailMessage.setSubject(Codes.verificationCode); //主题 mailMessage.setText(Codes.verificationCode+":"+verificationCode); // 内容 mailSender.send(mailMessage); // 发送 }
时间: 2024-10-30 01:45:43