登录&注册
This commit is contained in:
56
src/main/java/com/quinn/intergration/SendBMail.java
Normal file
56
src/main/java/com/quinn/intergration/SendBMail.java
Normal file
@@ -0,0 +1,56 @@
|
||||
package com.quinn.intergration;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import javax.mail.Authenticator;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.PasswordAuthentication;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Transport;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* 使用@multiavatar生成头像
|
||||
* https://api.multiavatar.com/
|
||||
*/
|
||||
public enum SendBMail {
|
||||
|
||||
INSTANCE;
|
||||
private static final Logger log = LoggerFactory.getLogger(SendBMail.class);
|
||||
final String username = "quinn.admin@88.com";
|
||||
final String password = "Y3YYd4hcY2fFB9VY";
|
||||
boolean isSSL = true;
|
||||
String host = "smtp.88.com";
|
||||
int port = 465;
|
||||
boolean isAuth = true;
|
||||
String from = "quinn.admin@88.com";
|
||||
|
||||
public boolean sendMail(String registerCode,String toEmail){
|
||||
Properties props = new Properties();
|
||||
props.put("mail.smtp.ssl.enable", isSSL);
|
||||
props.put("mail.smtp.host", host);
|
||||
props.put("mail.smtp.port", port);
|
||||
props.put("mail.smtp.auth", isAuth);
|
||||
Session session = Session.getDefaultInstance(props, new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
try {
|
||||
Message message = new MimeMessage(session);
|
||||
message.setFrom(new InternetAddress(from));
|
||||
message.setSubject("");
|
||||
message.setContent("","text/html;charset=UTF-8");
|
||||
message.addRecipient(Message.RecipientType.TO, new InternetAddress(toEmail));
|
||||
Transport.send(message);
|
||||
} catch (Exception e) {
|
||||
log.error("发送邮件失败",e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user