您好我有web应用程序java使用球衣,我部署我的程序与tomcat和连接到MySQL数据库...我有一个类负责发送邮件给用户。 localhost上一流的做工精细和邮件发送,但AFER我部署的方案,并上传到服务器犯规向用户发送邮件...我怎么能从web应用程序发送邮件
这个IHS的CLAS:
public static boolean SendMail(String from, String password, String message, String to[]) {
String host = "smtp.gmail.com";
Properties properties = System.getProperties();
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.host", host);
properties.put("mail.smtp.user", from);
properties.put("mail.smtp.password", password);
properties.put("mail.smtp.port", 587);
properties.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(properties, null);
MimeMessage mimeMessage = new MimeMessage(session);
try {
mimeMessage.setFrom(new InternetAddress(from));
InternetAddress[] toAddress = new InternetAddress[to.length];
for (int index = 0; index < to.length; index++) {
toAddress[index] = new InternetAddress(to[index]);
}
for (int index = 0; index < toAddress.length; index++) {
mimeMessage.addRecipient(Message.RecipientType.TO, toAddress[index]);
}
mimeMessage.setSubject("email From linkeride");
mimeMessage.setText(message);
Transport transport = session.getTransport("smtp");
transport.connect(host, from, password);
transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
transport.close();
return true;
} catch (MessagingException me) {
me.printStackTrace();
}
return false;
}
我也许有人可以告诉我问题是什么?
您的主机是否运行邮件服务器?如果您想进行一些测试,我知道有一种方法可以通过您的Gmail帐户管理电子邮件。至于制作推出,你需要一个邮件服务器来连接。 –
可能是您的服务器无法访问SMTP服务器或某个端口被阻止的简单情况。 –
是否有错误?您的网络是否需要网关进行此类连接? – Perdomoff