File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes javax.mail problem with Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "javax.mail problem with "cc" option." Watch "javax.mail problem with "cc" option." New topic
Author

javax.mail problem with "cc" option.

liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
Hi everyone, I'm still struggling getting "cc" option to work in my email application. At this point I have the following syntax for it:
if (!cc.equals("")){
InternetAddress arrCC[] = InternetAddress.parse(cc);
writer.println("arrCC SIZE : " + arrCC.length + "<br>");
//message.setRecipients(Message.RecipientType.CC, arrCC);
}

The commented out line is the line causing problems. When I use it, nothing works - email options "to" and "cc" both don't work, but no errors. I tried several syntax variation, but the result is the same.
Is there anyone who could tell me what can possibly help me with this?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Moving to Other Java APIs as this is not really servlet specific.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

I don't have any problems with that particular method in JDK 1.4.2_8.
Have you tried printing out the results of InternetAddress.parse to make sure your CC addresses are getting set correctly?
setRecipients will throw an exception in several circumstances. Are you handling such an exception correctly (i.e. informing the user their settings are incorrect or sending the email with just the TO being set)?


[How To Ask Questions On JavaRanch]
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
Thanks for responding.
I'm using JDK 1.5.0.
I did test parse method and the array looks good.
I have all my message code being caught by Throwable. If there are errors, I get fairly specific pointers to lines of code....
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

Can you show us a small sample of code that exhibits this behavior?
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
Here is a sniplet of my code:
try {
....
InternetAddress arrTO[] = InternetAddress.parse(to);
writer.println("arrTO SIZE : " + arrTO.length + "<br>");
message.setRecipients(Message.RecipientType.TO, arrTO);

for(int i=0; i<arrTO.length; i++)
writer.println("address: "+ arrTO[i].toString()+"<br>");

if (!cc.equals("")){
InternetAddress arrCC[] = InternetAddress.parse(cc);
message.setRecipients(Message.RecipientType.CC, arrCC);
for(int i=0; i<arrCC.length; i++)
writer.println("address: "+ arrCC[i].toString()+"<br>");
}
......
}catch (Throwable t) {
writer.println("<b>Unable to send message: <br><pre>");
t.printStackTrace(writer);
writer.println("</pre></b>");
}
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

I don't see anything obvious. You say that this code completes (i.e. you would see a log message from after the call to Transport.send()), right? Maybe your SMTP host is configured to prevent multiple CC's? (a wild guess on my part)
Can you run something simple like this:


If you can't run that, import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class test{
public static void main(String args[]){
try{
Properties props = new Properties();
props.put("mail.transport.protocol", "SMTP");
props.put("mail.smtp.host", "xxxxxxxx");
Session session = Session.getDefaultInstance(props, null);
MimeMessage msg = new MimeMessage(session);

// address our message
InternetAddress eccProb = new InternetAddress("xxxxxxx");
InternetAddress to = new InternetAddress("xxxxxxxx");
InternetAddress ccArr[] = new InternetAddress[2];
ccArr[0] = new InternetAddress("xxxxxxxx");
ccArr[1] = new InternetAddress("xxxxxxxx");

msg.setFrom(eccProb);

msg.setRecipients(Message.RecipientType.CC, ccArr);
msg.addRecipient(Message.RecipientType.TO, to);
msg.setSubject("This is a test");

// place the text in the message body
msg.setText("this is a test");

// send the message
Transport.send(msg);
} catch (Exception e){
e.printStackTrace();
}
}
}
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
Thank you for the code. I was able to compile and run the code no problem.
I don't think it did anything - didn't get any messages. Does it mean SMTP configuration needs to be reworked?
I know nothing about configuring SMTP. Yesterday I asked my network person about looking into it - she knew nothing about it either. So looking into SMTP configuration will be my next frontier.
Thank you for your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javax.mail problem with "cc" option.