How to read mime multipart messages in javamail - jakarta-mail

How to read mime multipart messages in javamail?
I want to display the message in webview.

Start with this JavaMail FAQ entry.
See also the msgshow.java demo program included with JavaMail.

Related

Apache Camel: What meaning of "attachments" in message model?

I read the book Camel in Action. But I can't understand what attachment mean in its message model.
I know headers such like sender information, receiver information, or data encoding etc. However, I don't know what is mean of attachments?
Lets run through some examples
You are consuming a file, camel can create a message with contents of the file as payload and file name etc as message headers
You are consuming a jms message, camel can create a message with contents of jms message as payload and jms header etc as message headers.
You are sending simple http request, camel can crate a message with what is inside the http request as paylaod and url etc as headers
Then you have some other components
You can send an email with some text in the body and some attachments, so in this case camel creates a message with payload, headers and attachments
You can also send SOAP request with attachments, in this case also, camel creates the message with payload, headers and attachments.
But there is not many camel components which support attachment. There is few like email, soap service etc

POST files using HTTP action - encoding problems

I have problems to upload attachments to JIRA REST API using HTTP POST with the HTTP action. It works with text files (Content-Type: text/plain) but when I'm posting other files such as PDF and images the files are not uploaded correctly; they get the wrong file size and are not readable.
I assume it's a problem with the encoding. I've tried to use the binary function on the file contents but it does not help. According to JIRA the REST API doesn't accept base64-encoded files.
Have anyone of you been successful in posting attachments (other than text files) to JIRA or another API?
I found how to do it. The body of the HTTP request should contain special attributes for Multipart and Content-Type as described here: https://learn.microsoft.com/en-us/azure/connectors/connectors-native-http#content-with-multipartform-data-type
So the HTTP POST should look like this:

Example of sending mail with attachment in gmail using api. How will the body request be like working example?

I have seen the API documentation still not getting it. Could someone give me the following :
1) The exact URL which I should use
2) The headers which I should use exactly
3) The Body Request which I should use
Could someone help me with it ??
For me worked: adding the attachments to the raw body of the request to the endpoint: https://www.googleapis.com/gmail/v1/users/userId/messages/send. This is tested with files up to 25MB.
I also couldn't figure out how to use the upload endpoint.
To add the attachment to the raw body i add a new Mime part (to the multipart/related) of type the same as the attachment mime type and you also need to add the Content-Disposition header to set if the attachment is inline or attached.
You can check here for more information on MIME messages:
https://www.qcode.co.uk/post/70

Ionic + Parse, need to parse Json to csv and send email with attachment

I'm looking for implementation for parsing Json object to csv and send it to a custom email address with the csv file as attachment.
Currently I'm using ionic + Mailgun for sending emails without attachments, but Mailgun dosen't support sending files.
many thanks in advance.
There is no real shortcut here. You'll need to iterate over your data set, generate the csv string and then write to file using cordova file plugin. Then you can either prompt the user to send the email by using the plugin cordova-plugin-email-composer to attach the file you've just saved OR find a service that lets you POST a file as part of the request, or write your own backend code to receive POST requests with the file to send the emails.

JavaMail - could not get body of text/plain message

I am writing a pop3 client using JavaMail to retrieve mails. But, I could not retrieve the body of the text/plain encoded mail messages.
The mail.getContent() is not fetching the body of the message. But mail.writeTo(System.out) is printing the complete mail data including the envelope information.
Is there any way to fetch only the body of the mail message?
Thanks!
Update: From the debug watch, I can see that mail.getContent() is only returning "\r\n".
Solution:
Seems like the problem is with mails sent directly from telnet session. The body of the mail is fetched propertly for mails sent from a smtp client program.
JavaMail is expecting a blank line (CRLF CRLF) to terminate the header block. When you enter the message via telnet, you're sending your system newline (which is probably just LF) at the end of each line you enter. So my guess is that JavaMail doesn't see the header/body separator it's expecting, and thus it's just tacking your "body" lines onto the end of its header block as malformed headers.

Resources