我想使用ip地址发送电子邮件
我正在尝试从javacode发送电子邮件,它写在下面
public static void sendEmailReminder(String emailid,String messageTosend ) {
String to=emailid;//change accordingly
Properties props = new Properties();
props.put("mail.smtp.host", "myIp");
props.put("mail.smtp.socketFactory.port", "25");
props.put("mail.smtp.port", "25");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("myId@yahoo.com","mypassword");//change accordingly
}
});
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress("myID@yahoo.com"));//change accordingly
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("Registration Details");
message.setText(messageTosend);
message.setContent(messageTosend, "text/html");
Transport.send(message);
System.out.println("message sent successfully");
} catch (MessagingException e) {throw new RuntimeException(e);}
}
按照http://www.yuki-onna.co.uk/email/smtp.html 在触发telnet之后,它应该显示输出为
telnet mail.domain.ext 25
Trying ???.???.???.???...
Connected to mail.domain.ext.
Escape character is '^]'.
220 mail.domain.ext ESMTP Sendmail ?version-number?; ?date+time+gmtoffset?
但是当我使用telnet时,我正在关注
home@linux-t0cw:~> telnet myIp 25
Trying myIp...
Connected to myIp.
Escape character is '^]'.
我没有得到最后一行,即
220 mail.domain.ext ESMTP Sendmail ?version-number?; ?date+time+gmtoffset?
此外,当我在java代码上运行时,我在控制台中没有得到任何东西,因为它需要花费很多时间连接到ip myIp。
请帮助我对此不熟悉,我不知道错误在哪里。