I have written some code to deal with multiple To addresses
Please go through it. But i am getting an error. Please help
public class Emailer
{
String subject;
String body;
Hashtable hashConfigParam = null;
Address fromAddr;
InternetAddress[] toAddr;
public Emailer()
{
hashConfigParam= new Hashtable();
hashConfigParam.put("host","202.202.230.211");
}
public Address setFromAddr(String fromEmailAddr) throws AddressException
{
fromAddr = new InternetAddress (fromEmailAddr);
return fromAddr;
}
public InternetAddress[] setToAddr(String[] toEmailAddr) throws AddressException
{
toAddr[] = new InternetAddress[] (toEmailAddr[]);
return toAddr;
}
public void sendEmail(String fromEmailAddr, String[] toEmailAddr, String ccEmailAddr, String aSubject, String aBody) throws AddressException
{
subject = aSubject;
body = aBody;
Address fAddr = setFromAddr(fromEmailAddr);
InternetAddress[] tAddr = setToAddr(toEmailAddr);
String h = (String)hashConfigParam.get("host");
Properties eMailConfigProps = null;
eMailConfigProps = System.getProperties();
eMailConfigProps.put("mail.smtp.host", h);
Session session = Session.getInstance(eMailConfigProps, null);
MimeMessage message = new MimeMessage(session);
try
{
message.setFrom(fAddr);
for(i=1; i<= tAddr.length ; i++)
{
message.addRecipient(Message.RecipientType.TO, new InternetAddress(tAddr));
}
message.addRecipient(Message.RecipientType.CC, new InternetAddress(ccEmailAddr));
message.setSubject(subject);
message.setText(body);
Transport.send(message);
}
catch (SendFailedException ex)
{
System.err.println("Cannot send email. " + ex);
}
catch (MessagingException ex)
{
System.err.println("Exception. " + ex);
}
}
error::
C:\trainee>javac Emailer.java
Emailer.java:29: not a statement
toAddr[] = new InternetAddress[] (toEmailAddr[]);
^
Emailer.java:29: ';' expected
toAddr[] = new InternetAddress[] (toEmailAddr[]);
^
2 errors