I want to save the url of attachment into mysql database in order to download it from mobile client (iphone) when user demand downloading attachment.
String disposition = part.getDisposition();
if (disposition != null && (disposition.equalsIgnoreCase("ATTACHMENT")))
// mail have attachment
I'm using this code to get the part of the message which is an attachment.
But i can't get it's url.
Any idea?
You should not try a url for attachment approach. For your attachments to have a url, you need a server that will hold all attachments, and you will to embed the url to an attachment in theemail, before it is sent out.. which can only be possible if te email is sent from your sysem.
You should instead look at it like asking a user before loading the attachment part of the message. If the user says yes, load the whole email, including the attachment.
Related
we use Java Mail to send E-Mails with PDF attachments via SMTP over Lotus Notes to our customers.
Some time ago we got notified that serveral customers don't received an attachment.
One of these customers uses Microsoft Outlook and got an attachment flag in his inbox. But when he opens the
E-Mail, he doesn't see an attachment. We don't have the possibility to check the version of the E-Mail client's
and to do customer side test's, because our customers are worldwide located.
If our customer responds or (internal) forward the E-Mail, the attachment shown in receiver's E-Mail client.
The following part is the affected Java source code:
private static Multipart createMultipartMailWithAttachment(String messageText)
throws MessagingException {
// Message with attachments
Multipart mp = new MimeMultipart();
// Attach Text
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(messageText, UTF8, HTML);
mp.addBodyPart(mbp1);
for (File f : attachments) {
MimeBodyPart fileAttachment = new MimeBodyPart();
try {
fileAttachment.setDisposition(MimeBodyPart.ATTACHMENT);
fileAttachment.attachFile(f);
if(f.getName().toLowerCase().endsWith(PDF_EXTENSION)) {
fileAttachment.setHeader(CONTENT_TYPE, APPLICATION_PDF);
}
} catch (IOException e) {
returnMessage = e.getMessage();
}
mp.addBodyPart(fileAttachment);
}
return mp;
}
We already tested different webmail services like gmail.com, yahoo.com and outlook.com. In every case the
attachment was shown. Also in an local installation of Mozilla Thunderbird, Microsoft Outlook or Lotus Notes
was the attachment shown.
After many inquiries we got many different solution processes. See setDisposition(MimeBodyPart.ATTACHMENT) and
setHeader(CONTENT_TYPE, APPLICATION_PDF). None of these solutions lead us to success. Does anyone know
a solution or a new solution process to solve that problem?
We had a similar problem where we sent file attachments from a J2EE application to various mail accounts. We utilized SMTP gmail server (smtp.gmail.com) with port 465 and HTTPS connection type for our outgoing messages.
Attachments to the messages sent via Java were not shown in Outlook but we could observe them in web interface for gmail accounts.
In our case, it turned out to be that MimeMultipart construction was not the correct one. We had
Multipart multipart = new MimeMultipart("alternative");
When we modified it to
Multipart multipart = new MimeMultipart();
the attachments became visible.
Please also refer to the following resource for a full explanation.
If messages sent from other mailers work properly and only messages sent from JavaMail fail, you'll need to examine the raw MIME content of the working and non-working messages to see what's different. You should be able to reproduce whatever content works using JavaMail.
There's lots of ways to access the raw MIME content of messages; let me know if you need help with that.
Obviously you'll need working and non-working examples messages with similar content to compare. If you have a repeatable test case - a message you can send to the same recipient multiple times and it fails every time - that would be most helpful.
I wanted to add a comment (question), but don't have the required points.
It could be a filter on the customer side that blocks attachments. See if the customer is getting a mail with attachment (same pdf) when sending it via normal outlook.
Second possible cause is the size of the attachment is a problem for the customer.
Third possible cause is that I have noticed that when I set up a rule to automatically put messages into a different folder, i see a message saying:
Links and other functionality have been disabled in this message. To turn on that functionality, move this message to the Inbox. Outlook blocked access to the potentially unsafe attachments: xxxx.pdf
Maybe this customer has setup a rule similarly.
i am trying to open outlook with attachment as follows:
Runtime.getRuntime().exec(
new String[] {"rundll32",
"url.dll,FileProtocolHandler",
"mailto:" + "&attachment=" + "c:\\test.txt"}
);
outlook opens, but it don't get the attachment, i don't know why ? please advise.
also is it possible to give the attachment web url from my application ?
like: http://myapp.com/files/123 (this link triggers file download)
mailto protocol does not support attachments. You would need to use the Outlook Object Model to explicitly create an instance of the Outlook.Application object, call Application.CreateItem() and then add the attachment using MailItem.Attachments.Add. You can then display the message using MailItem.Display.
i'm using java mail api to download java mail message attachment.
i am using this link tutorial
download mail attachment
but my requirement is that when user read mail it only display download link for attachment and when click on the link file downloaded that time.
Thanks
Manish
I think you want to do the following:
Check, if it is a multipart message AND consists of several parts
1.1 If so, it has attachments. You should then retrieve the first text/plain or text/html part, which should be the text itself. You leave the other parts alone. But along the text you store some id or reference to the message on the server, that the text is taken from. Consider the following code.
Folder folderInbox = store.getFolder("INBOX");
Message[] arrayMessages = folderInbox.getMessages();
for (int i = 0; i < arrayMessages.length; i++) {
Message message = arrayMessages[i];
}
Now the class javax.mail.Message has a method getMessageNumber()::int.
If you store this message number and the folder name, in this case "INBOX",
you have an identifier, that will allow you to find the message on the server
again at a later time and do something with it, like downloading parts that have
not been retrieved yet.
So (pseudo code here) you basically have to do this.
var message_text = message.getFirstTextBodyPart();
var message_ident = (message.getFolderName(), message.getMessageNumber());
var message = (message_ident, message_text);
saveMessage(message);
showMessage(message);
1.2 In other cases, you download the entire message right now, as there are no parts for later retrieval.
How to check the no. of attachments for the selected mail using imap?
I am able to get the message body/headers but I am not able get the attachment specific to mail selected?
Here is the code I tried:
DataHandler handler = message.getDataHandler();
AttachedFileName= handler.getName();
This code will give the filenames of all the attachments in the inbox and not specific to a mail.
How do I go about doing this?
Let me know!
you can increase a value for an integer when an attachment is finished.so,number of values increased is number of attachments .
It's a simple think too ..
I have a program which checks the unread email from an inbox, parses and sends the content of the email to a record. If there are any images in the email, those images will be sent as attachments to the record. Now if any email is having an image in the signature part of the email, that image is also being sent as an attachment.
Is there a way that I can check for the images in the signature part of the email and ignore them? or Is there a way around where I can skip the entire signature content from getting parsed?
Emails sent from outlook are high priority here. So Is there a particular standard in outlook of how the emails can be parsed for signatures?.