Page 1 of 1

Unable to send emails from the plugin

Posted: Thu Oct 17, 2013 4:04 pm
by bugi
Hi guys,
I am developing plugin for Oxygen editor.
Among other things it requires email sending form the plugin code.
I created email sending logic based on java mail api. It works fine when I run it from the unit test.
Once I wrap this email sending logic into the plugin and start Oxygen the email is not getting sent, no error messages, just silence.
I use smtp.jar, mail.jar and mailapi.jar in the class path
Am I missing something?

Please help!

Re: Unable to send emails from the plugin

Posted: Thu Oct 17, 2013 4:17 pm
by Radu
Hi,

So you added those required JAR libraries to the plugin.xml, right?
If you start Oxygen using the oxygen.bat command line executable, is there any error reported in the console?
If you wrap all your code in a

Code: Select all


try{
}catch(Exception ex){
ex.printStackTrace();
}
is there any exception stack trace reported in the console?

By the way, we have a topic which explains how you could test your plugin with Oxygen as a JUnit test case:

http://www.oxygenxml.com/doc/ug-oxygen/ ... tests.html

Regards,
Radu

Re: Unable to send emails from the plugin

Posted: Thu Oct 17, 2013 9:38 pm
by bugi
Yep,

I wrapped it up with try/catch. No errors detected but the email is not getting sent.

here is my email sending code
Properties properties = System.getProperties();
properties.put("mail.smtp.host", "smtp.gmail.com");
properties.put("mail.smtp.port", 587);
properties.put("mail.smtp.user", "XXX@gmail.com");
properties.put("mail.smtp.auth", true);
properties.put("mail.smtp.timeout", 60000);
properties.put("mail.smtp.starttls.enable", true);

Session session = Session.getInstance(properties,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("XXX@gmail.com", "ZZZ");
}
});

MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress("my@gmail.com"));
message.addRecipients(Message.RecipientType.TO, "yours@gmail.com");
message.setSubject("Subject");
message.setText("Email message!");
Transport.send(message);

Re: Unable to send emails from the plugin

Posted: Thu Oct 17, 2013 10:38 pm
by bugi
found the issue, there is a bug in the code that cut part of the receiver's email adress
Fixed that and everything works OK
Thx!