Jndi mail inyection and authentication.
carlosmarind Jul 27, 2016 1:05 PMhi guys,
Im trying to inject a jndi resource pointing to an email with the following definition in my standalone-full.xml :
<subsystem xmlns="urn:jboss:domain:mail:2.0">
<mail-session name="alertas" from="alertas@binaryoss.com" jndi-name="java:/mail/alertasMail" debug="true">
<custom-server name="mailAlertas" password="#######" username="alertas@binaryoss.com" outbound-socket-binding-ref="mail-smtp">
<property name="mail.smtp.auth" value="true"/>
<property name="mail.smtp.user" value="alertas@binaryoss.com"/>
<property name="mail.smtp.starttls.enable" value="true"/>
</custom-server>
</mail-session>
</subsystem>
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
<outbound-socket-binding name="mail-smtp">
<remote-destination host="mail.binaryoss.com" port="25"/>
</outbound-socket-binding>
</socket-binding-group>
the problem is that my mail server needs authentication for sending mails, and with this config no authentication is provided so the server complains about "relaying denied" when i send an email to another domain. I know that is because no authentication is submited and therefore no external domain is allowed to be mailed. ( only internal are permitted).
how can i provide authentication username and password with this jndi resource?
i leave a code segment for example:
@Resource(name = "java:/mail/alertasMail") | |
private Session mailSession; |
public boolean sendMail(Parameters params) { |
try { |
MimeMessage m = new MimeMessage(this.mailSession); | |||
InternetAddress[] to = new InternetAddress[] { new InternetAddress("carlosmarind@gmail.com") }; |
m.setRecipients(Message.RecipientType.TO, to); | |||
m.setSubject("Alerts"); | |||
m.setSentDate(new java.util.Date()); | |||
m.setText(this.constructContentGeoFence(), "utf-8", "html"); |
Transport.send(m); | |||
System.out.println("email sent"); |
return true; | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
return false; | |||
} |
} |
Thank you in advance.