Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

send mail

Help
2011-03-30
2013-04-16
  • Franco Morelli
    Franco Morelli
    2011-03-30

    Is it possible to add code in order to send a notification mail when an update event occurs?
    Thank you in advance for your help

     
  • Here's an example, careful to put the code in a module on the server side (or another object in the server side as Table, Service, WebService, WebRequest):

    import java.util.Properties;
    import java.util.Date;
    import java.mail.*;

    public sendMail(){
        scriptEngine.loadPlugin(dbSession.getPlugin("system.JavaMail"));
        var props = System.getProperties();
        props.put("mail.smtp.host", "localhost"); //HERE SMTP
        var session = javax.mail.Session.getDefaultInstance(props, null);
        var mimeMessage=new javax.mail.internet.MimeMessage(session);
        mimeMessage.setFrom(new javax.mail.internet.InternetAddress("info@dwprj.org")); //HERE FROM
        mimeMessage.setRecipients(javax.mail.Message.RecipientType.TO,"test@dwprj.org"); //HERE TO
        mimeMessage.setSubject("Subject …"); //HERE SUBJECT
        mimeMessage.setHeader("Content-Type","text/plain; charset=UTF-8");
        mimeMessage.setText("Message …","UTF-8"); //HERE MESSAGE
        mimeMessage.setSentDate(new Date());
        javax.mail.Transport.send(mimeMessage);
    }

    Best Regards
    Danilo Limatola