Email to SMS |
Written by Harry Fairhead | ||||||
Monday, 27 July 2009 | ||||||
Page 3 of 5
You have mailMoving on from making the connection and logging on to the server the first real task is to find out how many emails are waiting to be collected. To do this the client sends “STAT” and the server responses with “+OK n m” where n is the number of emails and m is the amount of storage used in bytes. Once you know this a NumEmails method is easy: public int NumEmails Once again we use a try-catch because if the constructor failed for any reason there isn’t a server open to query. In this case the catch clause simply returns 0 as the number of emails waiting. Notice the use of Split to divide the response text into three parts using spaces as the separator – “+Ok”, “n” and “m” and so the number of emails is in the second array element. We need a small method to mark emails for deletion. The POP3 command is “DELE n” where n is the number of the email to mark for deletion. Emails don’t actually get deleted unit the server receives the command “QUIT”: public void delMail(int n) |
||||||
Last Updated ( Wednesday, 18 November 2015 ) |