aspose file tools*
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "javax.mail servet/client issue " Watch "javax.mail servet/client issue " New topic
Author

javax.mail servet/client issue

liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
My email.java 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
Marshal

Joined: Mar 22, 2005
Posts: 41497
    
  53
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?


Ping & DNS - my free Android networking tools app
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("mail.smtp.host", 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))));
attachment.setFileName(filename);
String header = determineHeader(filename);
attachment.addHeader("Content-Type",header);
attachment.setDisposition("attachment");
Container.addBodyPart(attachment);


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

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);
}
message.setSubject(subject);
message.setContent(Container);
Transport.send(message);

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

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

Joined: Mar 22, 2005
Posts: 41497
    
  53
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: http://aspose.com/file-tools
 
subject: javax.mail servet/client issue