Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java mail attachment raw content appended to mail body

 
Versha Agarwal
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am  sending  attachment from Yahoo server.
My setting are:




Method to send mail is



sample of received file:

 
Paul Clapham
Sheriff
Posts: 21961
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dunno... you might want to have a look at this tutorial for example, which looks much like your code but has some minor (but possibly significant) differences.
 
Ron McLeod
Saloon Keeper
Posts: 1287
143
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Versha Agarwal wrote:I am  sending  attachment from Yahoo server ..

To be clear: you are sending the from a Java application through Yahoo, and somehow retrieving the email - is that correct?

How are you retrieving/viewing the email (the message that you included in your post) - do you have another Java application, are you using an email client?
 
Versha Agarwal
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron McLeod wrote:
Versha Agarwal wrote:I am  sending  attachment from Yahoo server ..

To be clear: you are sending the from a Java application through Yahoo, and somehow retrieving the email - is that correct?

How are you retrieving/viewing the email (the message that you included in your post) - do you have another Java application, are you using an email client?


I am opening it  using  my email id in gmail (using browser) https://mail.google.com/mail/u/0/#inbox
 
Versha Agarwal
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Versha Agarwal wrote:
Ron McLeod wrote:
Versha Agarwal wrote:I am  sending  attachment from Yahoo server ..

To be clear: you are sending the from a Java application through Yahoo, and somehow retrieving the email - is that correct?

How are you retrieving/viewing the email (the message that you included in your post) - do you have another Java application, are you using an email client?


I am opening it  using  my email id in gmail (using browser) https://mail.google.com/mail/u/0/#inbox


Yahho to yahho  is working fine.
But if recipient is gmail/rediff or any other it is not working.
 
Versha Agarwal
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Versha Agarwal wrote:
Versha Agarwal wrote:
Ron McLeod wrote:
Versha Agarwal wrote:I am  sending  attachment from Yahoo server ..

To be clear: you are sending the from a Java application through Yahoo, and somehow retrieving the email - is that correct?

How are you retrieving/viewing the email (the message that you included in your post) - do you have another Java application, are you using an email client?


I am opening it  using  my email id in gmail (using browser) https://mail.google.com/mail/u/0/#inbox


Yahho to yahho  is working fine.
But if recipient is gmail/rediff or any other it is not working.


Even I tried ByteArrayDataSource too. Same problem persists.
byte[] bFile = Files.readAllBytes(new File(path).toPath());
messageBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(bFile, "application/pdf")) );
multipart.addBodyPart(messageBodyPart);
 
Paul Clapham
Sheriff
Posts: 21961
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I dunno... you might want to have a look at this tutorial for example, which looks much like your code but has some minor (but possibly significant) differences.


Did you try this yet?
 
Ron McLeod
Saloon Keeper
Posts: 1287
143
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to run your code using my Gmail account and it worked fine.


One change that I made as to replace this
with this
I also enabled debugging in JavaMail
This is how the received email appeared on my email client




This is the debug output

I used version 1.4.2 of JavaMail
 
Versha Agarwal
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already  tried
String[] token = path.split("[\\\\|/]");
String filename = token[token.length - 1];

messageBodyPart.attachFile(path, "application/pdf", "base64");
Sending you debug output used with DataSource and messageBodyPart.setDataHandler()

 
Versha Agarwal
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sending you debug output used with messageBodyPart.attachFile(path, "application/pdf", "base64");

 
Versha Agarwal
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please try from yahoo server.
 
Ron McLeod
Saloon Keeper
Posts: 1287
143
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have a Yahoo account.  Maybe you should try sending from Gmail and see if you get the same (successful) result that I did.

Did you using messageBodyPart2.attachFile(path); to attach the document?
 
Versha Agarwal
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same method is working from another link.
But not for order pdf.
 
Ron McLeod
Saloon Keeper
Posts: 1287
143
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Versha Agarwal wrote:Same method is working from another link.  But not for order pdf.

Are you saying that some types of attachments get delivered as expected, but others do not?
 
Versha Agarwal
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even same type. I am able to send PDF from other link but it is not working for order.
 
Versha Agarwal
Greenhorn
Posts: 27
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem Solved.
In subject \r\n chracters was appended befor order code.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!