这是我的java代码发送电子邮件,每当我运行代码时它显示javax.mail.MessagingException:无法连接到SMTP主机:ipaddress,port:25; 我甚至尝试更改端口号,仍然是同样的错误..任何人都可以帮助我.. (我已将mail.jar和activation.jar包含在项目中)
public static void main(String arfs[]) throws UnknownHostException
{
InetAddress address = InetAddress.getLocalHost();
String to="gggg@gmail.com";
String from="vvvvv@gmail.com";
String host=address.getHostAddress();
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host",host);
properties.setProperty("mail.smtp.port", "25");
Session session = Session.getDefaultInstance(properties);
try{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress("vvvv@gmail.com"));
message.addRecipient(Message.RecipientType.TO,new InternetAddress("ggggg@gmail.com"));
message.setSubject("test email");
message.setText("hello");
Transport.send(message);
System.out.println("message sent successfully....");
}
catch(MessagingException mex)
{
mex.printStackTrace();
}
}
答案 0 :(得分:0)
检查您的系统是否具有SMTP访问权限?
答案 1 :(得分:0)
使用telnet进行测试时,是否收到SMTP问候语?
hash = window.location.hash.split('.')
document.getElementById(hash[0]).getElementsByClassName(hash[1])[0].scrollIntoView(true);
否=>这不是java的错误 您使用哪种操作系统/发行版?你有admin / root访问权限吗?