Here is my glassfish-resources.xml:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd"> <resources> <mail-resource debug="true" enabled="true" from=" foo@bar.com " host="smtp.mandrillapp.com" jndi-name="java:app/mail/mySession" object-type="user" store-protocol="imap" store-protocol-class="com.sun.mail.imap.IMAPStore" transport-protocol="smtp" transport-protocol-class="com.sun.mail.smtp.SMTPTransport" user=" foo@bar.com "> <description/> <property name="mail.user" value=" foo@bar.com "/> <property name="mail.password" value="password"/> <property name="mail.host" value="smtp.mandrillapp.com"/> <property name="mail.port" value="587"/> <property name="mail.smtp.socketFactory.port" value="587"/> <property name="mail.smtp.socketFactory.fallback" value="false"/> <property name="mail.smtp.auth" value="true"/> <property name="mail.smtp.starttls.enable" value="true"/> </mail-resource> </resources>
And email sending method:
public static void sendEmail(final Session session, final String from, final String to, final String subject, final String htmlPart, final String txtPart) throws AddressException, MessagingException { MimeMessage message = new MimeMessage(session); message.setSender(new InternetAddress(from)); InternetAddress toAddress = new InternetAddress(to); message.setRecipient(RecipientType.TO, toAddress); message.setSubject(subject);
When I call the above method, nothing happens. He comes to the end, with the exception of exceptions, but I do not receive emails from him.
Obviously, I configured it incorrectly because I was able to send emails via Mandrill using the mail client.
source share