• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

javax.mail problem with "cc" option.

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Other Java APIs as this is not really servlet specific.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)?
 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show us a small sample of code that exhibits this behavior?
 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Hold that thought. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic