Io ho questo codice:
Come faccio a inviarlo a più destinatari???codice:package javaapplication7; import javax.mail.*; import java.util.*; import javax.mail.internet.*; import javax.activation.*; import java.io.*; public class javamail { private String host = "smtp.gmail.com"; //tuo smtp private String from = "mioind@gmail.it"; //tuo indirizzo email private String user = "mioind"; private String ToAddress = "destinatario"; private String pass = "pass"; public javamail(String cella,String data_ita,int vuota) { try { //initialize the StringBuffer object within the try/catch loop StringBuffer sb = new StringBuffer( ); //Get system properties Properties props = System.getProperties( ); //Setup mail server props.put("mail.smtp.host", host); props.put("mail.smtp.starttls.enable","true"); props.put("mail.smtp.auth","true"); //Get session Session session = Session.getDefaultInstance(props, null); session.setPasswordAuthentication(new URLName("smtp",host,25,"INBOX",user,pass), new PasswordAuthentication(user,pass)); //Define message MimeMessage msg = new MimeMessage(session); //Set the from address msg.setFrom(new InternetAddress(from)); //Set the to address msg.addRecipient(Message.RecipientType.TO, new InternetAddress(ToAddress)); //Oggetto della mail msg.setSubject(cella+ ": mancanza data in DbFrigo"); if(vuota==1){ //Il corpo della mail sb.append("Nel database DbFrigo la "+cella+" non ha acquisito nessun dato in data "+data_ita); } if(vuota==0){ //Il corpo della mail sb.append("Nel database DbFrigo la "+cella+" non ha salvato dati negli ultimi 10 minuti"); } msg.setText(sb.toString( )); //Per inviare il messaggio Transport tr = session.getTransport("smtp"); tr.connect(host, user, pass); msg.saveChanges(); // don't forget this tr.sendMessage(msg, msg.getAllRecipients()); tr.close(); } catch (MessagingException e) { System.out.println(e); } } public static void main(String[] args) { javamail jv = new javamail("","",0); } }
Io avevo pensato di creare
ToAddress2 col 2° indirizzo di posta e poi mettere sotto la riga di comando
una riga identica con l'unico cambio di ToAddress2, così:codice:msg.addRecipient(Message.RecipientType.TO, new InternetAddress(ToAddress));
ma non mi ha funzionato...dove sbaglio????codice:msg.addRecipient(Message.RecipientType.TO, new InternetAddress(ToAddress)); msg.addRecipient(Message.RecipientType.TO, new InternetAddress(ToAddress2));

Rispondi quotando