You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.3 KiB
39 lines
1.3 KiB
package com.community.pocket.util;
|
|
|
|
import com.community.pocket.entity.po.EmailCode;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
import org.springframework.mail.MailException;
|
|
import org.springframework.mail.SimpleMailMessage;
|
|
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.Random;
|
|
|
|
@Service
|
|
public class EmailService {
|
|
@Autowired
|
|
private JavaMailSenderImpl javaMailSender;
|
|
|
|
@Autowired
|
|
private MongoTemplate mongoTemplate;
|
|
|
|
public boolean sendCode(String sender) {
|
|
SimpleMailMessage message = new SimpleMailMessage();
|
|
message.setSubject("口袋社区激活邮箱");
|
|
message.setText("欢迎注册口袋社区后台服务,您获取到的验证码是:xxxx");
|
|
message.setTo(sender);
|
|
message.setFrom("15920722180@163.com");
|
|
try {
|
|
javaMailSender.send(message);
|
|
EmailCode emailCode=new EmailCode();
|
|
emailCode.setCode(new Random().nextInt(1000)+"");
|
|
emailCode.setEmailAddress(sender);
|
|
mongoTemplate.save(emailCode);
|
|
return true;
|
|
} catch (MailException e) {
|
|
e.printStackTrace();
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|