I'm trying to make a program that picks up a list of members that contains the name, email, and renewal day (type of day pay monthly), and when it's the day, send an email to him.
But I have trouble getting the name and email of that particular member who is in the day to send the email. I tried to use socio[i]
(which is the name of the list), which is the number that entered for
.
In my if
, I am not able to compare day_of_month
with date, date is integer
and so it seems day_of_month
is of another type.
Follow my code to see if it helps me understand my problem
package trabalho2;
import java.util.ArrayList;
import java.util.Calendar;
import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
public class Main {
public static void main(String[] args) {
ArrayList <Socios> socios = new ArrayList();
//cadastrando os sócios
Socios socios1 = new Socios("Mateus", "[email protected]", 11);
Socios socios2 = new Socios("Eduardo Moya Simões", "[email protected]", 11);
//isso aqui é tipo colocando o q foi cadastrado na lista
socios.add(socios1);
socios.add(socios2);
Calendar c = Calendar.getInstance();
SimpleEmail email = new SimpleEmail();
email.setSSLOnConnect(true);
email.setHostName("smtp.googlemail.com");
email.setSslSmtpPort("465");
email.setAuthenticator( new DefaultAuthenticator( "[email protected]" , "nossasenha"));
for (int i = 0; i < socios.size(); i++) {
//isso só serve para vc ver como ta funcionando, depois tem q apagar
System.out.println("Socio: " + socios.get(i));
System.out.println(Calendar.DAY_OF_MONTH);
if (c.get(Calendar.DAY_OF_MONTH) = socios(i).getData) {
// função manda e-mail
try {
email.setFrom( "[email protected]", "Socio torcedor");
email.setDebug(true);
email.setSubject( "Pagamento fatura");
email.setMsg("Salve dpoente\n tu tem q pagar sua mensalidade né jumento");
email.addTo(socios.getEmail, socios.getNome);
email.send();
System.out.println("Email enviado para: " + socios.getEmail +" de " + socios.getNome);
}catch (EmailException e) {
e.printStackTrace();
}
}
}
}
}