@ApiOperation("测试邮箱") @GetMapping("/collectDetailsGetId2") public Result collectDetailsGetId2( ) throws MessagingException { Properties prop = new Properties(); prop.setProperty("mail.transport.protocol", "smtp");//定义邮件发送协议 prop.setProperty("mail.smtp.host", "smtp.qq.com");//声明邮件服务器地址 prop.setProperty("mail.smtp.auth", "true");//发送权限,为true时表示允许发送 prop.setProperty("mail.debug", "true");//设置为true时,调试的时候可以在控制台显示信息 Session session = Session.getInstance(prop);//相当于建立了一条通信路线 Message msg = new MimeMessage(session); try { msg.setFrom(new InternetAddress("15781xxxxx@qq.com","测试.","utf-8"));//发件者邮箱 } catch (UnsupportedEncodingException e) { e.printStackTrace(); } msg.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress("15781xxxxx@qq.com"));//收件邮箱 msg.setSubject("这是15781xxxxx发送给15781xxxxx的邮件XXXXXXXXXX"); //Date date = new Date(); msg.setText("嗨~你好"); Transport tran = session.getTransport(); tran.connect("15781xxxxx", "imtggnnay");//假设q号为15781xxxxx的密码为tssrhfsefguwdjbd (成功开启POP3/SMTP服务,在第三方客户端登录时,密码框请输入以下授权码:imtggnnay每个人不一样,开通看下面) tran.sendMessage(msg,msg.getAllRecipients()); return Result.success(""); }