ho questo metodo per inviare le mail riempiendo i campi in un JFrame:
il problema è che se nn gli passo anche un CC mi dice "Illegal address".codice:public class Mail { public static void send(String smtp, String to[], String cc[], String subject, String text) throws AddressException, MessagingException { Properties prop = System.getProperties(); prop.put("mail.smtp.host", smtp); Session session = Session.getDefaultInstance(prop, null); Message msg = new MimeMessage(session); InternetAddress addForm = new InternetAddress("matteo.ferrone@gmail.com"); msg.setFrom(addForm); InternetAddress[] addTo = new InternetAddress[to.length]; for (int i = 0; i < addTo.length; i++) { addTo[i] = new InternetAddress(to[i]); } msg.setRecipients(Message.RecipientType.TO, addTo); if (cc.length > 0) { InternetAddress[] addCc = new InternetAddress[cc.length]; for (int i = 0; i < addCc.length; i++) { addCc[i] = new InternetAddress(cc[i]); } msg.setRecipients(Message.RecipientType.CC, addCc); } msg.setSubject(subject); msg.setContent(text, "text/plain"); msg.setSentDate(null); Transport.send(msg); } }
quindi o gli passo un CC o commento tutta questa parte:
nel jframe ci stanno la jtext field per il TO e quella per il CC che vorrei poter lasciare anche vuota.codice:if (cc.length != 0) { InternetAddress[] addCc = new InternetAddress[cc.length]; for (int i = 0; i < addCc.length; i++) { addCc[i] = new InternetAddress(cc[i]); } msg.setRecipients(Message.RecipientType.CC, addCc); }

Rispondi quotando

