• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java mail attachment raw content appended to mail body

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am  sending  attachment from Yahoo server.
My setting are:




Method to send mail is



sample of received file:

 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sending you debug output used with messageBodyPart.attachFile(path, "application/pdf", "base64");

 
Versha Agarwal
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please try from yahoo server.
 
Ron McLeod
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Same method is working from another link.
But not for order pdf.
 
Ron McLeod
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 42
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem Solved.
In subject \r\n chracters was appended befor order code.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic