-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
  • 67,715
  • 15
  • 98
  • 113
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
  • 6,801
  • 5
  • 32
  • 55
0

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

InternetAddress[] address = {new InternetAddress(to)};
                         // ^                       ^
Andy Turner
  • 137,514
  • 11
  • 162
  • 243