<dependency> <groupId>javax.mail</groupId> <artifactId>javax.mail-api</artifactId> <version>1.6.2</version> </dependency> Properties properties = new Properties(); properties.put("mail.smtp.host", "smtp.example.com"); properties.put("mail.smtp.port", "587"); properties.put("mail.smtp.auth", "true"); Session session = Session.getInstance(properties, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("your-email@example.com", "your-password"); } }); Message message = new MimeMessage(session); message.setFrom(new InternetAddress("sender@example.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("receiver@example.com")); message.setSubject("Hello, World!"); message.setText("This is a test email."); Transport.send(message);


上一篇:
下一篇:
切换中文