我提出了我们的问题:
技术数据:Java,JSF
功能:使用SMTP协议发送邮件,
对于出站SMTP服务器smtp.gmail.com google完美运行:
public void envoisPassword(String mail, String password){
try {
/**
*initlisaser les variable
**/
Properties props = null;
SMTPTransport transport = null;
MimeMessage mimeMsg = null;
/**
* en va utliser le serveur stmp de gmail
* **/
props = System.getProperties();
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, null);
transport = (SMTPTransport)session.getTransport("smtp");
transport.connect("smtp.gmail.com", Integer.parseInt("587"), "adresse@gmail.com", "motdepass");
mimeMsg = new MimeMessage(session);
mimeMsg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(mail));
mimeMsg.setSender(InternetAddress.parse("adresse@gmail.com")[0]);
mimeMsg.setSubject("msg test ");
mimeMsg.setText("voici votre mot de passe : "+password);
transport.sendMessage(mimeMsg, mimeMsg.getAllRecipients());
transport.close();
} catch (Exception e) {
System.err.println(e.getCause());
}
}
当我们尝试使用域名托管服务器的SMTP传出服务器时,请注意。
执行在到服务器的连接线上停止:
transport.connect("hp181.hostpapa.com", Integer.parseInt("587"), *****@****.net","password");
服务器没有响应
感谢您的努力