We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,956 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Java mail Content

         String testHTMLContent = testhtml+productlogo;
         Message message = new MimeMessage(session);
         message.setFrom(new InternetAddress(usern));
         message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to));
         message.setRecipients(Message.RecipientType.CC,InternetAddress.parse(ccaddr));
         message.setSubject(sub);
         //message.setText(body);
         // setDebugMsg("Attempting to send...");
         Transport transport = session.getTransport("smtps");

         MimeMultipart mimeMultipart = new MimeMultipart();

         MimeBodyPart msgContent = new MimeBodyPart();
         msgContent.setContent(testcontent, "text/plain");
         mimeMultipart.addBodyPart(msgContent);


         MimeBodyPart query = new MimeBodyPart();
         query.setHeader("Content-Type", "text/plain");
         query.setContent(queryString, "text/plain");
         mimeMultipart.addBodyPart(query);

         MimeBodyPart htmlPart = new MimeBodyPart();
         htmlPart.setHeader("Content-Type", "text/html");
         htmlPart.setContent(testHTMLContent,"text/html");
         mimeMultipart.addBodyPart(htmlPart);

         attachedfile="filepath/attach.docx";
         if(attachedfile.length()!=0){
         MimeBodyPart attachmentContent = new MimeBodyPart();
         DataSource source = new FileDataSource(attachedfile);
         attachmentContent.setDataHandler(new DataHandler(source));
         attachmentContent.setFileName(attachedfile);
         mimeMultipart.addBodyPart(attachmentContent);
         }


         message.setContent(mimeMultipart);

         transport.connect("smtp.gmail.com", 465, usern, pass);
         Transport.send(message);
         transport.close();



         The above code is sending the only the resolution as content and the second text 'query' as attachment(.txt) and html content as .htm attachment. Please coorect the code..Thanks..
2
Contributors
2
Replies
1 Day
Discussion Span
7 Months Ago
Last Updated
3
Views
Hrithik516
Newbie Poster
21 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

ehm... correct the code? would you first mind telling us what your problem is? you are saying what it does. so, what is it supposed to do?

stultuske
Industrious Poster
4,372 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24

html part is supposed to appear as HTML Content,but it is coming as .htm attachment

Hrithik516
Newbie Poster
21 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0828 seconds using 2.75MB