public class MailSessionHandler extends Object
A wrapper around javax.mail.Store and javax.mail.Transport
Modifier and Type | Field and Description |
---|---|
protected boolean |
bIncomingSSL |
protected boolean |
bIsStoreConnected |
protected boolean |
bIsTransportConnected |
protected boolean |
bOutgoingSSL |
protected int |
iOutPortNum |
protected javax.mail.Session |
oMailSession |
protected javax.mail.Store |
oMailStore |
protected javax.mail.Transport |
oMailTransport |
protected Map<String,String> |
oProps |
protected javax.mail.Session |
oSmtpSession |
protected javax.mail.URLName |
oURLSession |
protected String |
sInAccountName |
protected String |
sInAuthStr |
protected String |
sInHostName |
protected String |
sMBoxDir |
protected String |
sOutAccountName |
protected String |
sOutAuthStr |
protected String |
sOutHostName |
Constructor and Description |
---|
MailSessionHandler()
Default constructor
|
MailSessionHandler(Map<String,String> oMailProperties)
Create session using given Properties
|
Modifier and Type | Method and Description |
---|---|
boolean |
checkPorts()
Checks to see if ports are available.
|
void |
close() |
String |
getAccountName()
Get column incoming_account of k_user_mail
|
String |
getAuthStr()
Get column incoming_password of k_user_mail
|
javax.mail.Folder |
getFolder(String sFolderName)
Get folder from current mail store
|
String |
getHostName()
Get column incoming_server of k_user_mail
|
String |
getMBoxDirectory() |
Map<String,String> |
getProperties() |
javax.mail.Session |
getSession()
Get incoming mail server Session
|
javax.mail.Session |
getSmtpSession()
Get outgoing mail server Session
|
javax.mail.Store |
getStore()
Get Store
|
javax.mail.Transport |
getTransport()
Get Transport
|
boolean |
isStoreConnected() |
boolean |
isTransportConnected() |
MailHeadersHelper[] |
listFolderMailMessagesHeaders(String sFolderName)
Get a list of headers for all folder messages which are not deleted
|
String[] |
listFolderMessages(String sFolderName)
Get a list of all folder messages which are not deleted
|
String[] |
listRecentMessages(String sFolderName,
int iMaxMsgs)
Get a list of most recent folder messages which are not deleted, answered or marked as spam
|
void |
sendMessage(javax.mail.Message oMsg) |
void |
sendMessage(javax.mail.Message oMsg,
javax.mail.Address[] aAddrs) |
void |
sendMessage(javax.mail.Message oMsg,
javax.mail.Address[] aAdrFrom,
javax.mail.Address[] aAdrReply,
javax.mail.Address[] aAdrTo,
javax.mail.Address[] aAdrCc,
javax.mail.Address[] aAdrBcc) |
int |
sendMessage(String sSubject,
String sFromPersonal,
String sFromAddr,
String sReplyAddr,
String[] aRecipients,
javax.mail.Message.RecipientType[] aRecType,
String sTextBody,
String sHtmlBody,
String sEncoding,
String sId,
String[] aAttachmentsPath,
String sUserDir,
boolean bInlineImages,
PrintStream oOut)
Send e-mail message
|
int |
sendMessage(String sSubject,
String sFromPersonal,
String sFromAddr,
String sReplyAddr,
String[] aRecipients,
javax.mail.Message.RecipientType[] aRecType,
String sTextBody,
String sHtmlBody,
String sEncoding,
String sId,
String[] aAttachmentsPath,
String sUserDir,
PrintStream oOut)
Send e-mail message
|
int |
sendMessage(String sSubject,
String sFromPersonal,
String sFromAddr,
String sReplyAddr,
String[] aRecipients,
javax.mail.Message.RecipientType oRecType,
String sTextBody,
String sHtmlBody,
String sEncoding,
String sId,
String[] aAttachmentsPath,
String sUserDir,
PrintStream oOut) |
void |
setAccountName(String aAccName)
Set incoming mail account name
|
void |
setAuthStr(String aAutStr)
Set incoming mail password
|
void |
setHostName(String sName)
Set incoming mail host name or IP address
|
void |
setMBoxDirectory(String sDir) |
void |
setProperties(Map<String,String> oPropties) |
protected String sInAccountName
protected String sInAuthStr
protected String sOutAccountName
protected String sOutAuthStr
protected String sInHostName
protected String sOutHostName
protected int iOutPortNum
protected String sMBoxDir
protected javax.mail.URLName oURLSession
protected javax.mail.Session oMailSession
protected javax.mail.Session oSmtpSession
protected javax.mail.Store oMailStore
protected javax.mail.Transport oMailTransport
protected boolean bIsStoreConnected
protected boolean bIsTransportConnected
protected boolean bIncomingSSL
protected boolean bOutgoingSSL
public MailSessionHandler()
public MailSessionHandler(Map<String,String> oMailProperties) throws NullPointerException
oMailProperties
- PropertiesProperty | Description> | Default value |
---|---|---|
mail.user | Store and transport user | |
mail.password | Store and transport password | |
mail.store.protocol | pop3 | |
mail.transport.protocol | smtp | |
mail.storeprotocol.host | For example: pop.mailserver.com | |
mail.storeprotocol.socketFactory.class | Only if using SSL set this value to javax.net.ssl.SSLSocketFactory | |
mail.storeprotocol.socketFactory.port | Only if using SSL | |
mail.transportprotocol.host | For example: smtp.mailserver.com | |
mail.transportprotocol.port | For example: 587 | |
mail.transportprotocol.socketFactory.class | Only if using SSL set this value to javax.net.ssl.SSLSocketFactory | |
mail.transportprotocol.socketFactory.port | Only if using SSL | |
proxySet | Use proxy | false |
socksProxyHost | Proxy IP address | |
socksProxyPort | Proxy Port | |
mail.smtp.debug | JavaMail Debug Mode | true or false (default) |
NullPointerException
- if oMailProperties is nullpublic String getAccountName()
Get column incoming_account of k_user_mail
public void setAccountName(String aAccName)
public String getAuthStr()
Get column incoming_password of k_user_mail
public void setAuthStr(String aAutStr)
public String getHostName()
Get column incoming_server of k_user_mail
public void setHostName(String sName)
public String getMBoxDirectory()
public void setMBoxDirectory(String sDir)
public javax.mail.Session getSession() throws IllegalStateException
Get incoming mail server Session
This method calls JavaMail Session.getInstance() method if neccesary, using properties currently set at this instance and SilentAuthenticator as Authenticator subclassIllegalStateException
NullPointerException
public javax.mail.Session getSmtpSession() throws IllegalStateException
Get outgoing mail server Session
This method calls JavaMail Session.getInstance() method if neccesary, using properties currently set at this instance and SilentAuthenticator as Authenticator subclassIllegalStateException
NullPointerException
public javax.mail.Store getStore() throws javax.mail.NoSuchProviderException, javax.mail.MessagingException
Get Store
This method calls Session.getStore() and Store.connect() if neccesary.javax.mail.NoSuchProviderException
javax.mail.MessagingException
public javax.mail.Transport getTransport() throws javax.mail.NoSuchProviderException, javax.mail.MessagingException
Get Transport
This method calls Session.getTransport() and Transport.connect() if neccesaryjavax.mail.NoSuchProviderException
javax.mail.MessagingException
public javax.mail.Folder getFolder(String sFolderName) throws javax.mail.NoSuchProviderException, javax.mail.MessagingException
javax.mail.NoSuchProviderException
javax.mail.MessagingException
public boolean isStoreConnected()
public boolean isTransportConnected()
public void sendMessage(javax.mail.Message oMsg) throws javax.mail.NoSuchProviderException, javax.mail.SendFailedException, javax.mail.internet.ParseException, javax.mail.MessagingException, NullPointerException, IllegalStateException
javax.mail.NoSuchProviderException
javax.mail.SendFailedException
javax.mail.internet.ParseException
javax.mail.MessagingException
NullPointerException
IllegalStateException
public String[] listFolderMessages(String sFolderName) throws javax.mail.AuthenticationFailedException, javax.mail.NoSuchProviderException, javax.mail.MessagingException
Get a list of all folder messages which are not deleted
Messages are returned in ascending date order, oldest messages are returned firstsFolderName
- Folder Name, for example: "INBOX"javax.mail.AuthenticationFailedException
javax.mail.NoSuchProviderException
javax.mail.MessagingException
public MailHeadersHelper[] listFolderMailMessagesHeaders(String sFolderName) throws javax.mail.AuthenticationFailedException, javax.mail.NoSuchProviderException, javax.mail.MessagingException
Get a list of headers for all folder messages which are not deleted
Messages are returned in ascending date order, oldest messages are returned firstsFolderName
- Folder Name, for example: "INBOX"javax.mail.AuthenticationFailedException
javax.mail.NoSuchProviderException
javax.mail.MessagingException
public String[] listRecentMessages(String sFolderName, int iMaxMsgs) throws javax.mail.AuthenticationFailedException, javax.mail.NoSuchProviderException, javax.mail.MessagingException, IllegalArgumentException
Get a list of most recent folder messages which are not deleted, answered or marked as spam
Messages are returned in descending date order, most recent messages are returned firstsFolderName
- Folder Name, for example: "INBOX"iMaxMsgs
- Maximum number of messages to get [1..2^31-1]javax.mail.AuthenticationFailedException
javax.mail.NoSuchProviderException
javax.mail.MessagingException
IllegalArgumentException
public void sendMessage(javax.mail.Message oMsg, javax.mail.Address[] aAddrs) throws javax.mail.NoSuchProviderException, javax.mail.SendFailedException, javax.mail.internet.ParseException, javax.mail.MessagingException, NullPointerException
javax.mail.NoSuchProviderException
javax.mail.SendFailedException
javax.mail.internet.ParseException
javax.mail.MessagingException
NullPointerException
public void sendMessage(javax.mail.Message oMsg, javax.mail.Address[] aAdrFrom, javax.mail.Address[] aAdrReply, javax.mail.Address[] aAdrTo, javax.mail.Address[] aAdrCc, javax.mail.Address[] aAdrBcc) throws javax.mail.NoSuchProviderException, javax.mail.SendFailedException, javax.mail.internet.ParseException, javax.mail.MessagingException, NullPointerException
javax.mail.NoSuchProviderException
javax.mail.SendFailedException
javax.mail.internet.ParseException
javax.mail.MessagingException
NullPointerException
public void close() throws javax.mail.MessagingException
javax.mail.MessagingException
public int sendMessage(String sSubject, String sFromPersonal, String sFromAddr, String sReplyAddr, String[] aRecipients, javax.mail.Message.RecipientType[] aRecType, String sTextBody, String sHtmlBody, String sEncoding, String sId, String[] aAttachmentsPath, String sUserDir, boolean bInlineImages, PrintStream oOut) throws NullPointerException, IOException, javax.mail.MessagingException, IllegalArgumentException, SecurityException
Send e-mail message
sSubject
- String e-mail SubjectsFromPersonal
- String Sender display namesFromAddr
- String Sender e-mail addresssReplyAddr
- String Reply-To e-mail addressaRecipients
- Array of recipients e-mail addressesaRecType
- Array of types for each recipient {to, cc, bcc}sTextBody
- String Plain Text Message BodysHtmlBody
- String HTML Text Message BodysEncoding
- Character Encoding to be usedsId
- String Message Unique Id. Optional, may be null.aAttachmentsPath
- Array of relative paths to files to be attachedsUserDir
- Base path for attached filesbInlineImages
- true is images will be inlined as attachments, false if they will be downloaded upon message openingoOut
- PrintStream Output stream for messages verboseNullPointerException
IOException
javax.mail.MessagingException
IllegalArgumentException
SecurityException
public int sendMessage(String sSubject, String sFromPersonal, String sFromAddr, String sReplyAddr, String[] aRecipients, javax.mail.Message.RecipientType[] aRecType, String sTextBody, String sHtmlBody, String sEncoding, String sId, String[] aAttachmentsPath, String sUserDir, PrintStream oOut) throws NullPointerException, IOException, javax.mail.MessagingException, IllegalArgumentException, SecurityException
Send e-mail message
sSubject
- String e-mail SubjectsFromPersonal
- String Sender display namesFromAddr
- String Sender e-mail addresssReplyAddr
- String Reply-To e-mail addressaRecipients
- Array of recipients e-mail addressesaRecType
- Array of types for each recipient {to, cc, bcc}sTextBody
- String Plain Text Message BodysHtmlBody
- String HTML Text Message BodysEncoding
- Character Encoding to be usedsId
- String Message Unique Id. Optional, may be null.aAttachmentsPath
- Array of relative paths to files to be attachedsUserDir
- Base path for attached filesoOut
- PrintStream Output stream for messages verboseNullPointerException
IOException
javax.mail.MessagingException
IllegalArgumentException
SecurityException
public int sendMessage(String sSubject, String sFromPersonal, String sFromAddr, String sReplyAddr, String[] aRecipients, javax.mail.Message.RecipientType oRecType, String sTextBody, String sHtmlBody, String sEncoding, String sId, String[] aAttachmentsPath, String sUserDir, PrintStream oOut) throws NullPointerException, IOException, javax.mail.MessagingException, IllegalArgumentException, SecurityException
NullPointerException
IOException
javax.mail.MessagingException
IllegalArgumentException
SecurityException
public boolean checkPorts()
Copyright © 2019. All rights reserved.