This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Servlets and the fly likes javax.mail servet/client issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "javax.mail servet/client issue " Watch "javax.mail servet/client issue " New topic

javax.mail servet/client issue

liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
My file works only on the server and not on the client side. The script gives no errors either; and doesn't work at all when try using "cc" mailing option, but this could be a separate issue.
Can anyone tell me what's happening?
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Without seeing a bit of relevant code, it's hard to tell what might be going on. Are you sure there isn't an exception somewhere that is inadvertently caught and not logged?
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
I use Throwable, so if there is an error, it would be caught.
I'm including the code producing the message... Please let me know if you see something strange there.

try {

//Get system properties
Properties props = System.getProperties();

//Specify the desired SMTP server
props.put("", mailHost);

// create a new Session object
Session session = Session.getInstance(props);

Message message = new MimeMessage(session);
Multipart Container = new MimeMultipart();

BodyPart attachment = new MimeBodyPart();
attachment.setDataHandler(new DataHandler(new FileDataSource(new File(filepath))));
String header = determineHeader(filename);

/**** text body of email ****/
BodyPart htmlText = new MimeBodyPart();
htmlText.setContent(body, "text/plain");

message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, new InternetAddress[] {
new InternetAddress(to) });

if (!cc.equals("")){
InternetAddress[] addresses = {new InternetAddress(cc) };
message.setRecipients(Message.RecipientType.CC, addresses);

// it worked!
writer.println("<b>message to " + to + " was successfully sent.</b>");

} catch (Throwable t) {
writer.println("<b>Unable to send message: <br><pre>");
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
So what happens when you run this? It just prints "message was sent" even if the message wasn't sent? Or does it send the message, but not to the CC, and then print the message?
Sarath Mohan
Ranch Hand

Joined: Mar 17, 2001
Posts: 213
I didn't get 'it is not working in client side'

May be it could not be able to locate mail servers.

Apache James is good starting point for dealing with Mailing applications. It provides a free SMTP, POP server and you can test stand alone mailing apps.

Sarath Mohan
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
When I run the code, no error happens. I test it in Firefox on the server and option "to" works fine alone, but if I try "cc" (with "to"), none of them work.
And if I test the code in IE - on a client machine, I can see the code pulling the data out (as long as I don't send an attachement - then I get an IO exception), says the message is sent - no errors, but option "to" doesn't work, and "cc" doesn't work...
I agree. Here's the link:
subject: javax.mail servet/client issue
It's not a secret anymore!