您好我有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