我已经导入了所有需要的api(smtp,邮件,激活) 没有错误,使用Java
并没有给我代码正确的提示属性props =新的Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
Session session = Session.getDefaultInstance(props,new Authenticator()
{
@Override
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("javafx.****@gmail.com", "******");
}
});
try
{
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("javafx.tuto@gmail.com"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("heno.qadd97@gmail.com"));
message.setSubject("message");
message.setText("Hello world");
Transport.send(message);
System.out.println("Email sended!");
} catch (MessagingException e)
{
System.out.print("Something happened!");
throw new RuntimeException(e);
}
}