ÎļþÃû´Ó src/main/java/com/yssh/utils/EmailUtils.java ÐÞ¸Ä |
| | |
| | | package com.yssh.utils; |
| | | package com.yssh.service; |
| | | |
| | | import com.yssh.utils.StringUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.mail.*; |
| | | import javax.mail.internet.InternetAddress; |
| | |
| | | import java.util.Properties; |
| | | |
| | | /** |
| | | * é®ä»¶å·¥å
·ç±» |
| | | * é®ä»¶æå¡ç±» |
| | | * |
| | | * @author www |
| | | * @date 2024-03-21 |
| | | */ |
| | | public class EmailUtils { |
| | | @Service |
| | | public class EmailService { |
| | | @Value("${email.userName}") |
| | | private String userName; |
| | | |
| | |
| | | // å建ä¸ä¸ªé
ç½®æä»¶ï¼å¹¶ä¿å |
| | | Properties props = new Properties(); |
| | | |
| | | // SMTPæå¡å¨è¿æ¥ä¿¡æ¯ï¼126âsmtp.126.comï¼163âsmtp.163.comï¼qq-qqsmtp.qq.com" |
| | | // SMTPæå¡å¨è¿æ¥ä¿¡æ¯ï¼126âsmtp.126.comï¼163âsmtp.163.comï¼qq-smtp.qq.com" |
| | | props.put("mail.smtp.host", smtpHost); // SMTP主æºå |
| | | props.put("mail.smtp.port", smtpPort); // 主æºç«¯å£å·ï¼126â25ï¼163â645 |
| | | props.put("mail.smtp.port", smtpPort); // 主æºç«¯å£å·ï¼126â25ï¼163â645ï¼qq-587 |
| | | props.put("mail.smtp.auth", smtpAuth); // æ¯å¦éè¦ç¨æ·è®¤è¯ |
| | | props.put("mail.smtp.starttls.enale", smtpTls); // å¯ç¨TlSå å¯ |
| | | |
| | |
| | | return session; |
| | | } |
| | | |
| | | public void send(String title, String text) { |
| | | public Boolean send(String title, String text) { |
| | | try { |
| | | // å建Sessionä¼è¯ |
| | | Session session = createSession(); |
| | |
| | | |
| | | // åé |
| | | Transport.send(message); |
| | | |
| | | return true; |
| | | } catch (Exception ex) { |
| | | logger.error(ex.getMessage(), ex); |
| | | return false; |
| | | } |
| | | } |
| | | } |