|
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.EmailAccount
public class EmailAccount
EmailAccount provides an easy way to send and receive emails 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 the javax.mail API or J2EE
JNewsletterManager,
JEmailClient,
EmailAccountTableModel| Constructor Summary | |
|---|---|
EmailAccount()
convenience constructor that uses null values (and 'your@email' as 'from'-address; parameters must be changed before use |
|
EmailAccount(File configFile)
|
|
EmailAccount(Properties props)
|
|
EmailAccount(String pop3Server,
String smtpServer,
String user,
String password,
String from,
boolean authentication)
|
|
EmailAccount(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 |
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. |
static Email |
extractEmail(javax.mail.Message msg)
|
boolean |
getAccessInboxBeforeSend()
false by default |
boolean |
getAuthentication()
|
boolean |
getDebug()
|
String |
getFrom()
|
javax.mail.Folder |
getInbox()
returns the POP3 inbox from the given mail settings. |
Logger |
getLogger()
|
String |
getPassword()
|
String |
getPop3Server()
|
String |
getSmtpPassword()
|
String |
getSmtpServer()
|
String |
getUser()
|
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(EmailAccount account)
calls loopTest(account, 30, 5*60). |
boolean |
loopTest(EmailAccount account,
int waitBetweenTriesInSeconds,
int timeOutInSeconds)
this method tests this email account externally against the given account for its sending/receiving capabilities. |
boolean |
loopTest(int waitBetweenTriesInSeconds,
int timeOutInSeconds)
this method tests this email account fully regarding its send/receive functionality. |
Email[] |
receiveEmails()
fully downloads all messages from the inbox into Email objects (the messages remain on the server) |
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 EmailAccount[] |
retrieveAccountsFromFile(File file)
constructs EmailAccount objects from a file containing the necessary configuration data. |
static void |
saveAccountsToFile(EmailAccount[] 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)
all settings (including from address) is taken from the given Message object |
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 |
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 |
setLogger(Logger logger)
|
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 |
setSession()
recreates the embedded session and accounts for possibly changed System settings |
void |
setSmtpPassword(String smtpPassword)
must only be set explicitly if different from the POP3 password |
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 EmailAccount()
throws javax.mail.NoSuchProviderException,
javax.mail.internet.AddressException
javax.mail.NoSuchProviderException
javax.mail.internet.AddressException
public EmailAccount(File configFile)
throws IOException,
javax.mail.NoSuchProviderException,
javax.mail.internet.AddressException
IOException
javax.mail.NoSuchProviderException
javax.mail.internet.AddressException
public EmailAccount(Properties props)
throws javax.mail.NoSuchProviderException,
javax.mail.internet.AddressException
javax.mail.NoSuchProviderException
javax.mail.internet.AddressException
public EmailAccount(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 EmailAccount(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| Method Detail |
|---|
public void setSession()
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 Logger getLogger()
public void setLogger(Logger logger)
public void setAccessInboxBeforeSend(boolean flag)
public boolean getAccessInboxBeforeSend()
public Email[] receiveEmails()
throws javax.mail.MessagingException,
IOException
javax.mail.MessagingException
IOException
public javax.mail.Folder getInbox()
throws javax.mail.MessagingException
javax.mail.MessagingException
public javax.mail.Message[] receiveMessages()
throws javax.mail.MessagingException
Message.getFolder(boolean) method after processing the returned
messages.
If the number of returned messages is 0, the store is closed automatically.
javax.mail.MessagingException
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.MessagingException
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.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(EmailAccount account)
loopTest(account, 30, 5*60).
loopTest(EmailAccount, int, int)
public boolean loopTest(EmailAccount 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 static Email extractEmail(javax.mail.Message msg)
throws javax.mail.MessagingException,
IOException
javax.mail.MessagingException
IOException
public static EmailAccount[] retrieveAccountsFromFile(File file)
throws IOException,
ParseException,
javax.mail.NoSuchProviderException,
javax.mail.internet.AddressException
IOException
ParseException
javax.mail.NoSuchProviderException
javax.mail.internet.AddressException(EmaliAccount[], File)
public static void saveAccountsToFile(EmailAccount[] accounts,
File file)
throws IOException
IOExceptionretrieveAccountsFromFile(File)
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||