We want to write a program using Java Mail-1.5 that can append the message of Gmail to Yahoo account. Is this possible with Java Mail API? What we are trying is that we have downloaded eml of Gmail message at our system, now we want to append these messages to one Yahoo account. On trying this we are getting this errors -
javax.mail.MessagingException: A4 NO [SERVERBUG] LIST Server error - Please try again later;
nested exception is: com.sun.mail.iap.CommandFailedException: A4 NO [SERVERBUG] LIST Server error - Please try again later
at com.sun.mail.iap.Protocol.handleResult(Protocol.java:351)
at com.sun.mail.imap.protocol.IMAPProtocol.doList(IMAPProtocol.java:1100)
at com.sun.mail.imap.protocol.IMAPProtocol.list(IMAPProtocol.java:1046)
at com.sun.mail.imap.IMAPFolder$1.doCommand(IMAPFolder.java:518)
at com.sun.mail.imap.IMAPFolder.doProtocolCommand(IMAPFolder.java:2991)
at com.sun.mail.imap.IMAPFolder.doCommand(IMAPFolder.java:2931)
... 8 more
Sometime this process producing similar errors as some are below listed -
A33 NO Invalid "flag-list" : Contains unsupported flag or other invalid item.
A18 BAD [CLIENTBUG] APPEND Command arguments invalid
A19 BAD [CLIENTBUG] APPEND Command arguments invalid
A21 NO [SERVERBUG] LIST Server error - Please try again later
A12 BAD [CLIENTBUG] APPEND Command arguments invalid
.............
............
Is this possible to append message of Gmail (eml) to Yahoo account using Java Mail API??
Thanks,
Neelam Sharma
This is really a question about what the Yahoo mail server supports. As you've discovered, the Yahoo mail server sometimes fails operations due to a "server bug". It may take a few retries to get the operation to work.
The APPEND failure seems to be due to the server limiting what flags you can set when you append the message. The debug output will show you what flags it's trying to set. You might need to clear those flags in the message before appending the message.
See the JavaMail populate.java demo program, and in particular the dontPreserveFlags option in that program.
Related
I am fetching the emails from the POP server.
I am using the following logic to find the mail which is received newly.
if(currentMail.getSentTime() > lastMailFetchedTime)
{
//Processing the email
}
else
{
System.out.println("Mail sent earlier. It might be fetched already");
}
At regular time interval , Some emails are missed from the POP mail fetcher(For Google Apps account). I have analyzed the mail fetching process and identified that, POP server is giving the older emails which is not given in the previous mail fetching.
Is Gmail POP server provides the mail based on the mail sent time(I am not getting it in proper order)?
If it is not given using the mail sent time means, How can I fetch the newly created emails without using IMAP ?
Think of the POP3 server as storing messages in a sequential list where the last message in the list is always the most recently received message.
So essentially it "sorts" them in order of arrival, but this might not be the same as "Date Sent".
POP3 server is automatically sorted messages, but only up to minutes.
Context:
I am working on a piece of Java code where I am reading mails from an array (which works fine). I was wondering if someone can help me with the callback in order to show a fancy message like Your email was sent.
Questions:
How do I implement this?
Is there any way to get any Boolean type return value from javax.mail to check if the message was sent or not?
Maybe I should create a pool? If yes, how do I do that? Is there any signal to kill the pool?
Code:
// addressTo is the array.
Transport t = sesion.getTransport(this.beanMail.getProtocolo());
t.connect(this.beanMail.getUsuario(), this.beanMail.getPassword());
t.sendMessage(mensaje, addressTo);
t.close();
Quoting from the JavaMail API FAQ (in the context of tracking bounced messages):
While there is an Internet standard for reporting such errors (the multipart/report MIME type, see RFC1892), it is not widely implemented yet. RFC1211 discusses this problem in depth, including numerous examples.In Internet email, the existence of a particular mailbox or user name can only be determined by the ultimate server that would deliver the message. The message may pass through several relay servers (that are not able to detect the error) before reaching the end server. Typically, when the end server detects such an error, it will return a message indicating the reason for the failure to the sender of the original message. There are many Internet standards covering such Delivery Status Notifications but a large number of servers don't support these new standards, instead using ad hoc techniques for returning such failure messages. This makes it very difficult to correlate a "bounced" message with the original message that caused the problem. (Note that this problem is completely independent of JavaMail.)
Source
Here is what I am trying to do:
Add a special button to attach files to Notes "New message" window. If files were attached using this button, when email sent, they should be uploaded to the server and link to them added to the email.
My question - is it possible (and how) to capture "send mail" event in the plugin for Lotus Notus?
I don't know how an Eclipse plugin would do this. Furthermore, since Notes can be used off-line -- when it would be impossible to upload files to a server -- it would be better to have code running on the Domino server intercept the mail messages and perform the upload.
Most products that hook mail operations on the server use the Lotus Notes C API's Extension Manager functions to hook the EM_BEFORE notification for the EM_NSFNOTEUPDATE event and check whether the NSFNoteUpdate operation occurred within the server's mail.box files, and then check whether the the message requires special processing (i.e., in your case that would be by looking for a special NotesItem that your button code has inserted into the message). The usual coding method for this is to immediately change the status of the message to put it on hold, preventing the Domino router from attempting to send the message while your code is still working on it. Many products actually have two components - the EM hook DLL and a separate server task that receives a signal from the hook DLL, processes the message, and then releases it from on hold status. This approach keeps your code from tying up router threads while processing large files.
(Note: Newer versions of the Domino server have the ability to use OSGI plugins written in Java instead of using the Notes C API for operations like this. I've not looked into the details of how this might work for operations that process mail messages. )
I sort of figured it out. There is a very nice extension point provided in 8.5 - "com.ibm.notes.mailsend.MailSendAttachmentsDialog", that is specifically exists for custom handling of attachments. You can see it in plugin.xml, in IBM\Lotus\Notes\framework\shared\eclipse\plugins\com.ibm.notes.mailsend_8.5.*.jar.
The only problem is - it handles just attachments and does not have access to anything else. So if somebody figured how to get subject line and the message text from there, please reply.
Update: got it.
NotesUIElement elem = (new NotesUIWorkspace()).getCurrentElement();
if (elem instanceof NotesUIDocument) {
NotesUIDocument doc = ((NotesUIDocument) elem);
String to = doc.getField("EnterSendTo").getText();
String cc = doc.getField("EnterCopyTo").getText();
String bcc = doc.getField("EnterBlindCopyTo").getText();
String subject = doc.getField("Subject").getText();
String body = doc.getField("Body").getText();
....
}
When writing a connection to connect to the POP3 protocol through sockets, I could use the LIST command to get the list of emails. Suppose I do a LIST command, it returns 3700 mails in the list. I read the whole response into a buffer. Now, I want to list these mails one by one on my application.
LIST
1 1472
...
3696 3224
3697 5998
3698 1970
3699 1425
3700 129345
.
I had 2 ideas in mind. First, I could parse the response line by line and get the message number of the message. And for each line I get the message number, say #3700, I do a TOP 3700 10. So this would read 10 lines of the mail headers. At first, I thought this would be good because I don't have to do a download the entire mail just for the subject, name, from address and some bit of brief content of the email; I could save the traffic. But the problem is not all emails have only 10 lines of headers. Some emails have extremely long headers while others are very short. It is difficult to determine how many lines to read. Not only that, because the email is not entirely downloaded, when the user wants to read the full mail, I have to send another RETR command to get the whole email. Then suppose if there were another connection to the POP account and deleted the message #3700. My application still recognise the email by this "non-unique" message id. When my application wants to download the email and sends a RETR 3700, it will respond with a -ERR Server Unavailable. 21
The second idea I have is then to use a RETR 3700. This would read the whole mail, just for that few information to list it in the application. I thought this is kind of silly because if the mailbox has a lot of mails, I am retrieving the entire mailbox into the application's memory!
What are the common/clever ways an email client would handle the mails from the POP server?
PS: I am not using the JavaMail because the intention is to learn more about how the POP protocol works and the implementations used to work with the protocols.
The 2nd argument of TOP command is a non-negative number of message lines to download - header lines are not included.
You can use TOP command with 0 as line count (TOP message_number 0) to download only message headers.
I was trying to see if there was a way to search an email inbox from javax.mail. Say I wanted to send a query and have the it return emails to us. Can we parse returned HTML and extract data. Also, if the above is possible how would I "translate" those messages returned by that server to POP3 messages? E.g. we have extracted:
Subject: Foo
Body: Bar
but to open same message using POP3 I need to know it's POP3 uid, or number. I don't think we'll be able to get UID but perhaps we can figure out the number.
I guess the question is:
Can I send a query to email server (such as Hotmail or Yahoo) and get returned emails?
Unfortunately, the POP3 protocol doesn't support that. It is not like SQL or so. You need to mirror the complete mailbox yourself in some kind of a datastore (SQL database?) and execute the search on that. You can eventually keep/cache the data so that you don't need to retrieve the whole inbox everytime, but only the unread items.