Es konnte keine Verbindung zu SMTP host: localhost, port: 25?
bin mit liferay 6 und erstellt eine benutzerdefinierte Klasse..ich möchte das erstellen von mail-notification-Funktion...die ich geschrieben habe folgenden code in meiner Klasse
private void SendEmail(NotificationObject pNotificatonObj,
String[] pReciepientAddresses) throws MessagingException {
log.info("In SendMail");
Properties props = new Properties();
props.put("mail.debug", "true");
props.put("mail.smtp.socketFactory.fallback", "false");
Session session = Session.getInstance(props);
Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(
pNotificatonObj.get_From());
msg.setFrom(addressFrom);
//InternetAddress addressTo = new
//InternetAddress(pNotificatonObj.get_To());
InternetAddress[] addressTo = new InternetAddress[pReciepientAddresses.length];
log.info("ADDRESS ARRAY LENGTH In Send Mail: - " + pReciepientAddresses.length);
for (int i = 0; i < pReciepientAddresses.length; i++) {
log.info("ADDRESS ARRAY LENGTH In Send Mail: - " + pReciepientAddresses[i]);
addressTo[i] = new InternetAddress(pReciepientAddresses[i]);
}
//log.info("INTERNET ADRESS ARRAY LENGTH : - " + addressTo1.length);
msg.setRecipients(RecipientType.TO, addressTo);
//msg.addRecipients(Message.RecipientType.TO, addressTo);
//Setting the Subject and Content Type
msg.setSubject(pNotificatonObj.get_Subject());
msg.setContent(pNotificatonObj.get_HtmlString().toString().toString(),
"text/html");
Transport.send(msg);
log.info("Send Mail Leave");
}
Ich geschrieben habe folgende Dinge in meinem root.xml Datei tomcatserver Verzeichnis
<Resource
name="mail/MailSession"
auth="Container"
type="javax.mail.Session"
mail.imap.host="localhost"
mail.pop.host="localhost"
mail.store.protocol="imap"
mail.transport.protocol="smtp"
mail.smtp.host="smtp.gmail.com"
mail.smtp.port="465"
mail.smtp.auth="true"
mail.smtp.starttls.enable="true"
mail.smtp.user="[email protected]" //MyEmailId
password="*******" //My password
mail.smtp.socketFactory.class="javax.net.ssl.SSLSocketFactory"
/>
Aber sein gibt mir folgenden Fehler ...kann jemand bitte helfen Sie mir..wo mache Fehler
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect
Du musst angemeldet sein, um einen Kommentar abzugeben.
Keiner dieser Eigenschaften sind Sie in Ihrer Einstellung root.xml die Datei wird von Ihrer Anwendung verwendet werden.
Müssen Sie Ihre Anwendung ändern, suchen Sie die JavaMail-Session mit JNDI erstellen, anstatt Sie selbst mit Session.netInstance, oder müssen Sie Ihre Anwendung ändern, um alle diese Eigenschaften auf die Eigenschaften von Objekt, das Sie verwenden, um erstellen Sie die neue Session-Objekt.
Vergessen Sie nicht, Lesen Sie die JavaMail-FAQ für häufige Fehler und wie eine Verbindung zu Gmail. (Tipp: Sie brauchen keine der socketFactory Eigenschaften).