0
正在使用的Liferay 6和创建一个自定义class..i要创建邮件通知功能......我已经写在我的课无法连接到SMTP主机:localhost,端口:25?
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");
}
我已经在我的ROOT.xml文件写入以下的事情下面的代码tomcatserver目录
<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"
/>
但它给我下面的错误...谁能帮我out..where正在做错误
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect
我已经做了你说的方式...我已经把下面的代码放在我的portal-ext-porperties文件中mail.session.jndi.name = mail/MailSession但我仍然有同样的错误 –
对不起,我不明白你做了什么。你把什么“下面的代码”放在哪里?也许你可以发布你尝试过的更新代码和配置? –
请参阅http://stackoverflow.com/a/8924168/535646如何访问您的JNDI设置。 –