eversor
|
Posted: September 10, 2009 12:58 by eversor
|
|
Hi, I observe a rather peculiar behaviour when I send mails over STMP. I stripped my problem case down to this code: MimeMessage message; message = new MimeMessage(javax.mail.Session.getDefaultInstance(props)); message.setFrom(new InternetAddress("recipient@domain.com")); message.setRecipients(Message.RecipientType.TO, "recipient@domain.com"); message.setSubject("subject"); Multipart multipart = new MimeMultipart(); // prepare the attachment MimeBodyPart attachment = new MimeBodyPart(); attachment.setDataHandler(new DataHandler(new URL( "http://localhost:8080/TestJersey/helloworld"))); attachment.setFileName("name.ext"); // prepare the body MimeBodyPart body = new MimeBodyPart(); body.setContent("body", "text/plain"); // add the attachment to the mail multipart.addBodyPart(attachment); // add the body to the mail multipart.addBodyPart(body); // finalize mail message.setContent(multipart); // send the mail log.info("Sending"); Transport.send(message); log.info("Sent"); Now when the mail is send, the URL (http://localhost:8080/TestJersey/helloworld) of the attachment is called three times. The server part is a very simple Jersey installation and looks something like this (without imports): @Path("/helloworld") public class HelloWorld { private static Logger log; static { try { FileHandler handler = new FileHandler( "log-server.txt"); log = Logger.getLogger("test"); log.addHandler(handler); } catch (IOException e) { e.printStackTrace(); } } @GET @Produces("text/plain") public String sayHello() { log.info("Servlet called"); return "Hello World"; } } This can't be the expected behaviour or is it? |
When sending a message, attachment with URL gets called multiple times
Replies: 1 - Last Post: September 15, 2009 03:45
by: shannon
by: shannon
showing 1 - 2 of 2
Replies: 1 - Last Post: September 15, 2009 03:45
by: shannon
by: shannon







