|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.net.mail.POP3Account
@ThirdParty(value="javax.email") public class POP3Account
EmailAccount provides an easy way to send and receive emails via POP3/SMTP through an application. A special feature is the ability to send the same email body to lots of individual addresses, such as a customized newsletter. Note that this class is not to be used for unsolicited bulk email, but its purpose is solely to be used for legitimate subscribers of proper newsletters that abide to the appropriate Internet rules! The bulk email feature for newsletters currently only supports text messages. EmailAccount requires at least javax.mail API 1.4.2
JNewsletterManager,
EmailClientFrame,
EmailAccountTableModel| Nested Class Summary | |
|---|---|
static class |
POP3Account.Config
encapsulates the configuration for an EmailAccount |
| Constructor Summary | |
|---|---|
POP3Account()
convenience constructor that uses null values (and 'from@email' as 'from'-address; parameters must be changed before use |
|
POP3Account(File configFile)
|
|
POP3Account(POP3Account.Config settings)
|
|
POP3Account(Properties props)
uses the following property keys: pop3Server, smtpServer, user, password,
from and authentication |
|
POP3Account(Properties props,
String keyPrefix)
|
|
POP3Account(String pop3Server,
String smtpServer,
String user,
String password,
String from,
boolean authentication)
|
|
POP3Account(String pop3Server,
String smtpServer,
String user,
String password,
String from,
boolean authentication,
Logger logger)
|
|
| Method Summary | |
|---|---|
void |
abortActions()
allows to cancel long-running operations, such as loopTest() |
javax.mail.internet.MimeMessage |
createMessage(Email email)
if no 'from' address is configured, the embedded 'from' address is used |
javax.mail.internet.MimeMessage |
createTextMessage(String subject,
String body)
from-address is taken from this object's configuration |
boolean |
delete(Email email)
|
boolean |
delete(javax.mail.Message msg)
|
boolean |
delete(String messageId)
|
int |
deleteFromInbox(int maxMessagesToDelete)
returns the number of messages actually deleted from the POP3 inbox |
int |
emptyInbox()
returns the number of messages deleted from the POP3 inbox |
static void |
expungePop3Message(javax.mail.Message msg)
the associated folder must subsequently be closed with the flag set to true to actually delete the message from the inbox. |
Email |
extractEmail(javax.mail.Message msg)
|
String[] |
fetchMessageIDs()
|
boolean |
getAccessInboxBeforeSend()
false by default |
boolean |
getAuthentication()
|
boolean |
getDebug()
|
String |
getFrom()
|
Vector<Email.Header> |
getHeaders()
|
javax.mail.Folder |
getInbox()
returns the POP3 inbox from the given mail settings. |
Logger |
getLogger()
acess to the (non-null) Logger suitable for logging entries in the context of this instance |
static int |
getMXCount(String hostName)
looks up the 'MX'-record of the given hostName to see how many email servers are running (code taken from public domain) |
String |
getPassword()
|
String |
getPop3Server()
|
Processor<javax.mail.Message,? extends Exception> |
getSendProcessor()
|
javax.mail.Session |
getSession()
|
POP3Account.Config |
getSettings()
returns a new instance of Settings; changing the returned instance will have no effect on this instance |
String |
getSmtpPassword()
|
int |
getSmtpPort()
|
String |
getSmtpServer()
|
com.sun.mail.smtp.SMTPTransport |
getTransport()
|
String |
getUser()
|
void |
init(POP3Account.Config settings)
|
void |
initSession()
recreates the embedded session and accounts for possibly changed System settings |
boolean |
isRequireStartTLS()
|
boolean |
isSmtpOverSSL()
|
Iterator<javax.mail.Message> |
iterator()
note that if there were any messages, the folder is left open until you close it |
javax.mail.internet.MimeMessage |
load(File emlFile)
|
javax.mail.internet.MimeMessage |
load(InputStream in)
|
static javax.mail.internet.InternetAddress[] |
loadAddressesFromFile(File file)
calls loadAddressesFromText(String) |
static javax.mail.internet.InternetAddress[] |
loadAddressesFromText(String text)
each address is assumed to be in an individual line. |
boolean |
loopTest()
calls loopTest(20, 2*60). |
boolean |
loopTest(int waitBetweenTriesInSeconds,
int timeOutInSeconds)
this method tests this email account fully regarding its send/receive functionality. |
boolean |
loopTest(POP3Account account)
calls loopTest(account, 30, 5*60). |
boolean |
loopTest(POP3Account account,
int waitBetweenTriesInSeconds,
int timeOutInSeconds)
this method tests this email account externally against the given account for its sending/receiving capabilities. |
Email[] |
receiveEmails(boolean removeFromServer)
fully downloads all messages from the inbox into Email objects |
javax.mail.Message[] |
receiveMessages()
retrieves all messages from the INBOX but doesn't download the content. |
void |
resetAbortStatus()
resets the abort status, so that operations can normally proceed |
static POP3Account[] |
retrieveAccountsFromFile(File file)
constructs EmailAccount objects from a file containing the necessary configuration data. |
static void |
saveAccountsToFile(POP3Account[] accounts,
File file)
|
void |
send(Email email)
all settings (including from address) is taken from the given Email object |
void |
send(javax.mail.Message msg)
sends out the given message after it ran through the processor (if applicable). |
void |
send(String to,
String subject,
String messageBody)
sends out a simple text email message |
void |
send(String to,
String subject,
String messageBody,
File attachment)
sends an email with a file attachment. |
void |
sendEmails(Email email,
javax.mail.internet.InternetAddress[] recipients)
sends the email individually to each address. |
void |
sendEmails(Email email,
javax.mail.internet.InternetAddress[] recipients,
EmailCustomizer replacerCallback,
Monitor monitor)
sends the email individually to each address. |
void |
setAccessInboxBeforeSend(boolean flag)
may be necessary for special ISPs that have that requirement |
void |
setAllFrom(POP3Account account)
copies the properties of the given object and applies them to this instance, so that its behavior in regards to the given object can be matched to the extend that the implementing class supports that behavior. |
void |
setAuthentication(boolean flag)
|
void |
setDebug(boolean flag)
|
void |
setFrom(String from)
|
static void |
setHeaders(javax.mail.Message msg,
Email.Header[] header)
all headers keys and values must be String objects |
void |
setPassword(char[] pwd)
|
void |
setPassword(String password)
sets both, the pop3 password and the smtp password; if the smtp password is different, it must be set herafter. |
void |
setPop3Server(String pop3Server)
|
void |
setRequireStartTLS(boolean flag)
used to support GoogleMail, for example |
void |
setSendProcessor(Processor<javax.mail.Message,? extends Exception> processor)
allows to set a processor that will handle messages before they get sent |
void |
setSmtpOverSSL(boolean smtpOverSSL)
|
void |
setSmtpPassword(String smtpPassword)
must only be set explicitly if different from the POP3 password |
void |
setSmtpPort(int smtpPort)
default is 25; for SSL: 465; alternatively: 587 |
void |
setSmtpServer(String smtpServer)
|
void |
setSmtpUser(String smtpUser)
must only be set explicitly if different from the POP3 user |
void |
setUser(String user)
sets both, the pop3 user and the smtp user; if the smtp user is different, it must be set herafter. |
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public POP3Account()
throws javax.mail.NoSuchProviderException,
javax.mail.internet.AddressException
javax.mail.NoSuchProviderException
javax.mail.internet.AddressException
public POP3Account(File configFile)
throws IOException,
javax.mail.NoSuchProviderException,
javax.mail.internet.AddressException
IOException
javax.mail.NoSuchProviderException
javax.mail.internet.AddressException
public POP3Account(Properties props)
throws javax.mail.NoSuchProviderException,
javax.mail.internet.AddressException
pop3Server, smtpServer, user, password,
from and authentication
javax.mail.NoSuchProviderException
javax.mail.internet.AddressException
public POP3Account(Properties props,
String keyPrefix)
throws javax.mail.NoSuchProviderException,
javax.mail.internet.AddressException
javax.mail.NoSuchProviderException
javax.mail.internet.AddressException
public POP3Account(String pop3Server,
String smtpServer,
String user,
String password,
String from,
boolean authentication)
throws javax.mail.NoSuchProviderException,
javax.mail.internet.AddressException
javax.mail.NoSuchProviderException
javax.mail.internet.AddressException
public POP3Account(String pop3Server,
String smtpServer,
String user,
String password,
String from,
boolean authentication,
Logger logger)
throws javax.mail.NoSuchProviderException,
javax.mail.internet.AddressException
javax.mail.NoSuchProviderException
javax.mail.internet.AddressException
public POP3Account(POP3Account.Config settings)
throws javax.mail.NoSuchProviderException,
javax.mail.internet.AddressException
javax.mail.NoSuchProviderException
javax.mail.internet.AddressException| Method Detail |
|---|
public void setAllFrom(POP3Account account)
Forgeable
setAllFrom in interface Forgeable<POP3Account>account - the object whose behavior is to be copied to this instance
public void init(POP3Account.Config settings)
throws javax.mail.NoSuchProviderException
javax.mail.NoSuchProviderExceptionpublic POP3Account.Config getSettings()
init(Config)public javax.mail.Session getSession()
public com.sun.mail.smtp.SMTPTransport getTransport()
public void initSession()
throws javax.mail.NoSuchProviderException
javax.mail.NoSuchProviderException
public void setRequireStartTLS(boolean flag)
throws javax.mail.NoSuchProviderException
javax.mail.NoSuchProviderExceptionpublic boolean isRequireStartTLS()
public int getSmtpPort()
public void setSmtpPort(int smtpPort)
throws javax.mail.NoSuchProviderException
javax.mail.NoSuchProviderExceptionpublic boolean isSmtpOverSSL()
public void setSmtpOverSSL(boolean smtpOverSSL)
throws javax.mail.NoSuchProviderException
javax.mail.NoSuchProviderExceptionpublic boolean getDebug()
public void setDebug(boolean flag)
throws javax.mail.NoSuchProviderException
javax.mail.NoSuchProviderExceptionpublic String getPop3Server()
public void setPop3Server(String pop3Server)
throws javax.mail.NoSuchProviderException
javax.mail.NoSuchProviderExceptionpublic String getSmtpServer()
public void setSmtpServer(String smtpServer)
throws javax.mail.NoSuchProviderException
javax.mail.NoSuchProviderExceptionpublic String getUser()
public void setUser(String user)
throws javax.mail.NoSuchProviderException
javax.mail.NoSuchProviderException
public void setSmtpUser(String smtpUser)
throws javax.mail.NoSuchProviderException
javax.mail.NoSuchProviderExceptionpublic String getPassword()
public String getSmtpPassword()
public void setPassword(char[] pwd)
public void setPassword(String password)
public void setSmtpPassword(String smtpPassword)
public String getFrom()
public void setFrom(String from)
throws javax.mail.internet.AddressException
javax.mail.internet.AddressExceptionpublic boolean getAuthentication()
public void setAuthentication(boolean flag)
throws javax.mail.NoSuchProviderException
javax.mail.NoSuchProviderExceptionpublic Vector<Email.Header> getHeaders()
public Logger getLogger()
LoggerProvider
getLogger in interface LoggerProviderpublic void setAccessInboxBeforeSend(boolean flag)
public boolean getAccessInboxBeforeSend()
public Email[] receiveEmails(boolean removeFromServer)
throws javax.mail.MessagingException,
IOException
javax.mail.MessagingException
IOException
public boolean delete(Email email)
throws javax.mail.MessagingException
javax.mail.MessagingException
public boolean delete(javax.mail.Message msg)
throws javax.mail.MessagingException
javax.mail.MessagingException
public boolean delete(String messageId)
throws javax.mail.MessagingException
javax.mail.MessagingException
public javax.mail.Folder getInbox()
throws javax.mail.MessagingException
javax.mail.MessagingException
public String[] fetchMessageIDs()
throws javax.mail.MessagingException
javax.mail.MessagingException
public javax.mail.Message[] receiveMessages()
throws javax.mail.MessagingException
Message.getFolder().close(boolean) method after processing the returned
messages.
If the number of returned messages is 0, the store is closed automatically.
javax.mail.MessagingExceptiongetInbox()public Iterator<javax.mail.Message> iterator()
iterator in interface Iterable<javax.mail.Message>getInbox()
public int emptyInbox()
throws javax.mail.MessagingException
javax.mail.MessagingException
public int deleteFromInbox(int maxMessagesToDelete)
throws javax.mail.MessagingException
javax.mail.MessagingException
public void send(String to,
String subject,
String messageBody)
throws javax.mail.MessagingException
to - may be a comma or semicolon separated list of addresses
javax.mail.MessagingException
public void send(String to,
String subject,
String messageBody,
File attachment)
throws javax.mail.MessagingException
to - may be a comma or semicolon separated list of addresses
javax.mail.MessagingException
public void send(Email email)
throws javax.mail.MessagingException
javax.mail.MessagingException
public void send(javax.mail.Message msg)
throws javax.mail.MessagingException
javax.mail.MessagingExceptiongetSendProcessor()public Processor<javax.mail.Message,? extends Exception> getSendProcessor()
setSendProcessor(Processor)public void setSendProcessor(Processor<javax.mail.Message,? extends Exception> processor)
send(Message)
public void sendEmails(Email email,
javax.mail.internet.InternetAddress[] recipients)
throws javax.mail.MessagingException
javax.mail.MessagingException
public void sendEmails(Email email,
javax.mail.internet.InternetAddress[] recipients,
EmailCustomizer replacerCallback,
Monitor monitor)
throws javax.mail.MessagingException
javax.mail.MessagingException
public javax.mail.internet.MimeMessage createMessage(Email email)
throws javax.mail.MessagingException
javax.mail.MessagingException
public javax.mail.internet.MimeMessage createTextMessage(String subject,
String body)
throws javax.mail.MessagingException
javax.mail.MessagingException
public javax.mail.internet.MimeMessage load(File emlFile)
throws javax.mail.MessagingException,
IOException
javax.mail.MessagingException
IOException
public javax.mail.internet.MimeMessage load(InputStream in)
throws javax.mail.MessagingException
javax.mail.MessagingExceptionpublic String toString()
toString in class Objectpublic boolean loopTest()
loopTest(20, 2*60).
loopTest(int, int)
public boolean loopTest(int waitBetweenTriesInSeconds,
int timeOutInSeconds)
waitBetweenTriesInSeconds - number of seconds to wait before a retrytimeOutInSeconds - number of seconds after which the method will time out
and not try anymore to receive the test message
public boolean loopTest(POP3Account account)
loopTest(account, 30, 5*60).
loopTest(POP3Account, int, int)
public boolean loopTest(POP3Account account,
int waitBetweenTriesInSeconds,
int timeOutInSeconds)
waitBetweenTriesInSeconds - number of seconds to wait before a retrytimeOutInSeconds - number of seconds after which the method will time out
and not try anymore to receive the test messageaccount - the account used to test this account against
public void abortActions()
loopTest()
resetAbortStatus(),
loopTest()public void resetAbortStatus()
abortActions()
public static void setHeaders(javax.mail.Message msg,
Email.Header[] header)
throws javax.mail.MessagingException
javax.mail.MessagingException
public static void expungePop3Message(javax.mail.Message msg)
throws javax.mail.MessagingException
msg - must be a com.sun.mail.pop.POP3Message object
javax.mail.MessagingException
public static javax.mail.internet.InternetAddress[] loadAddressesFromFile(File file)
throws IOException,
javax.mail.internet.AddressException
loadAddressesFromText(String)
IOException
javax.mail.internet.AddressException
public static javax.mail.internet.InternetAddress[] loadAddressesFromText(String text)
throws javax.mail.internet.AddressException
javax.mail.internet.AddressException
public Email extractEmail(javax.mail.Message msg)
throws javax.mail.MessagingException,
IOException
javax.mail.MessagingException
IOException
public static POP3Account[] retrieveAccountsFromFile(File file)
throws IOException,
ParseException,
javax.mail.NoSuchProviderException,
javax.mail.internet.AddressException
IOException
ParseException
javax.mail.NoSuchProviderException
javax.mail.internet.AddressExceptionsaveAccountsToFile(POP3Account[], File)
public static void saveAccountsToFile(POP3Account[] accounts,
File file)
throws IOException
IOExceptionretrieveAccountsFromFile(File)
public static int getMXCount(String hostName)
throws NamingException
NamingException
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||