Forums Register Login

javax.mail servet/client issue

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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>");
}
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 was her plaything! And so was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 866 times.
Similar Threads
pop up in jsp
http response problem
Special Characters exchange between windows
urgent help - java.net.SocketException: Connection reset by peer: socket write error
Disabling all submit actions(i.e all submit buttons) on a jsp page
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 05:12:55.