-1

I'm trying to create a send email function in netbeans and it says

"incompatible types: InternetAddress cannot be converted to InternetAddress[]".

When I write InternetAddress[] address = new InternetAddress[10](); it complains about a ; missing.

mailSession.setDebug(sessionDebug);
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = (new InternetAddress(to));


msg.setRecipients(Message.RecipientType.TO, address); 
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);
Jens
  • 60,806
  • 15
  • 81
  • 95
Lorvan
  • 3
  • 2

2 Answers2

0

Instead of

InternetAddress[] address = (new InternetAddress(to));


msg.setRecipients(Message.RecipientType.TO, address); 

Use

msg.setRecipients(Message.RecipientType.TO, new InternetAddress(to)); 
Ninad Pingale
  • 5,634
  • 4
  • 24
  • 45
0

() are not the right brackets to use for array initialization. Use {} instead:

InternetAddress[] address = {new InternetAddress(to)};
                         // ^                       ^
Andy Turner
  • 122,430
  • 10
  • 138
  • 216