嗨,当我在家用电脑上尝试以下代码时,它工作正常。
Properties props=new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", 465);
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", true);
props.put("mail.smtp.port", 465);
Session sess=Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication("user email ID","password");
}
});
try{
Message msg=new MimeMessage(sess);
msg.setFrom(new InternetAddress("sunnykeerthi@gmail.com"));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("sunnykeerthi@gmail.com"));
msg.setSubject("Hi this is mail");
msg.setText("Hi this is an email sent from java");
Transport.send(msg);
JOptionPane.showMessageDialog(null, "message has been sent");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
但是当我在我的办公室电脑上尝试相同的操作时,它给了我附加屏幕中的错误。 请帮忙。