how to send message to mailing list with apache mail?

I am working on an application to send emails with javafx and apache mail commons, but it throws and error when i try to send the message.

Caused by: javax.mail.internet.AddressException: Illegal address in 
string `` ''
at javax.mail.internet.InternetAddress.<init>(
at org.apache.commons.mail.Email.createInternetAddress(
... 59 more

Anyways i noticed when i initialize the array of strings with my recipients it sends it correctly, but if i take them from the database it throws the error i wrote above.

The way it works.

HtmlEmail email = new HtmlEmail();
String[] emails = {"", ""}

The way it doesn't work

HtmlEmail email = new HtmlEmail();
String[] emails = model.getEmailsBy(campaignName); //Returns a string[]

Important: model.getEmailsBy(campaignName); is not null.

1 answer

  • answered 2018-03-13 20:45 Christopher

    there must be at least one blank or invalid email in the list of model.getEmailsBy(campaignName); and this is the reason of Illegal address in string `` ''.