| | |
| | | |
| | | import com.ruoyi.common.config.MailProperties; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.sun.xml.internal.org.jvnet.mimepull.MIMEMessage; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.Properties; |
| | | import javax.mail.*; |
| | | import javax.mail.internet.InternetAddress; |
| | | import javax.mail.internet.MimeMessage; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.util.Properties; |
| | | |
| | | @Component |
| | | @Slf4j |
| | |
| | | // 访问SMTP服务时需要提供的密码(在控制台选择发信地址进行设置) |
| | | props.put("mail.password", properties.getPassword()); |
| | | props.setProperty("mail.smtp.socketFactory.fallback", "false"); |
| | | props.put("mail.smtp.ssl.enable", "false"); |
| | | props.put("mail.smtp.ssl.enable", "true"); |
| | | props.put("mail.smtp.ssl.protocols", "TLSv1.2"); |
| | | // 构建授权信息,用于进行SMTP进行身份验证 |
| | | Authenticator authenticator = new Authenticator() { |
| | | @Override |
| | |
| | | //发送邮件 |
| | | Transport.send(message); |
| | | } catch (MessagingException | UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | log.error("发送邮件发生异常",e); |
| | | throw new ServiceException("发送邮件失败,请检查"); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | log.error("发送邮件发生异常",e); |
| | | } |
| | | |
| | | } |
| | | |
| | | // public static void main(String[] args) { |
| | | // TencentMailUtil tencentMailUtil = new TencentMailUtil(); |
| | | // MailProperties properties = new MailProperties(); |
| | | // tencentMailUtil.properties = properties; |
| | | // tencentMailUtil.send("214491528@qq.com","大学城揽院24栋"); |
| | | // |
| | | // } |
| | | public static void main(String[] args) { |
| | | TencentMailUtil tencentMailUtil = new TencentMailUtil(); |
| | | MailProperties properties = new MailProperties(); |
| | | tencentMailUtil.properties = properties; |
| | | tencentMailUtil.send("645025773@qq.com","大学城揽院24栋"); |
| | | |
| | | } |
| | | |
| | | |
| | | |