Ciao a tutti ho creato una classe, per l'invio della posta, che provvedo ad allegare.

Premesso che lanciata singolarmente la classe funziona perfettamente.

Quando provo ad invocarla da un'altra classe mi da un messaggio di errore.

Qualcuno sa come invocare questa classe?

Ciao.
codice:
public class SendAMail {

    private static final String SMTP_HOST_NAME = "smtp.gmail.com";
    private static final int SMTP_HOST_PORT = 465;
    private static final String SMTP_AUTH_USER = "XXXXXXXXXXXXXXX@gmail.com";
    private static final String SMTP_AUTH_PWD  = "XXXXXXXXXXXXXXXX";

    public static void main(String[] args) throws Exception{
       new SendAMail().test();
    }

    public void test() throws Exception{
        Properties props = new Properties();

        props.put("mail.transport.protocol", "smtps");
        props.put("mail.smtps.host", SMTP_HOST_NAME);
        props.put("mail.smtps.auth", "true");
        props.put("mail.smtps.quitwait", "false");

        Session mailSession = Session.getDefaultInstance(props);
        mailSession.setDebug(true);
        Transport transport = mailSession.getTransport();

        MimeMessage message = new MimeMessage(mailSession);
        message.setSubject("Testing SMTP-SSL");
        message.setContent("TESTO MESSAGGIO DI POSTA", "text/plain");
        message.addRecipient(Message.RecipientType.TO,
             new InternetAddress("XXXXXXXXXXXXX@gmail.com"));

        transport.connect
          (SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);

        transport.sendMessage(message,
            message.getRecipients(Message.RecipientType.TO));
        transport.close();
    }
}