我在我的 java GWT 应用程序中使用此代码
public String greetServer(String input) throws Exception {
try{
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.smtp.port", "25");
props.setProperty("mail.host", "smtp.random.com");
props.setProperty("mail.user", "foo@bar.com");
props.setProperty("mail.password", "000000000");
Session mailSession = Session.getDefaultInstance(props, null);
Transport transport = mailSession.getTransport();
MimeMessage message = new MimeMessage(mailSession);
message.setSubject("hello");
message.setContent("helloo sss", "text/plain");
message.addRecipient(Message.RecipientType.TO, new InternetAddress("junaidp@gmail.com"));
transport.connect();
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
transport.close();
} catch(NoSuchProviderException e){
throw new Exception(e);
}
return input;
}
错误:javax.mail.MessagingException:无法连接到 SMTP 主机:smtp.random.com,端口:25;嵌套异常是:java.net.ConnectException:连接被拒绝:连接
如果我使用
props.setProperty("mail.host", "smtp.live.com");
and use my hotmail account , it gives this error
javax.mail.MessagingException: can't determine local email address
任何想法可能是解决方案
谢谢