public class GreenMailUtil extends Object
Modifier and Type | Method and Description |
---|---|
static void |
copyStream(InputStream src,
OutputStream dest)
Writes the content of an input stream to an output stream
|
static MimeMessage |
createTextEmail(String to,
String from,
String subject,
String msg,
ServerSetup setup) |
static String |
getAddressList(Address[] addresses) |
static String |
getBody(Part msg) |
static byte[] |
getBodyAsBytes(Part msg) |
static byte[] |
getHeaderAsBytes(Part part) |
static String |
getHeaders(Part msg) |
static int |
getLineCount(String str) |
static Quota[] |
getQuota(GreenMailUser user,
String quotaRoot)
Gets the quotas for the user.
|
static Session |
getSession(ServerSetup setup) |
static Session |
getSession(ServerSetup setup,
Properties mailProps)
Gets a JavaMail Session for given server type such as IMAP and additional props for JavaMail.
|
static String |
getWholeMessage(Part msg) |
static boolean |
hasNonTextAttachments(Part m) |
static GreenMailUtil |
instance()
Deprecated.
As of 1.5 and to be removed in 1.6. No need to instantiate static helper class
|
static MimeMessage |
newMimeMessage(InputStream inputStream)
Convenience method which creates a new
MimeMessage from an input stream. |
static MimeMessage |
newMimeMessage(String mailString)
Convenience method which creates a new
MimeMessage from a string |
static String |
random()
Generates a random generated password consisting of letters and digits
with a length variable between 5 and 8 characters long.
|
static String |
random(int nbrOfLetters) |
static void |
sendAttachmentEmail(String to,
String from,
String subject,
String msg,
byte[] attachment,
String contentType,
String filename,
String description,
ServerSetup setup) |
static void |
sendMessageBody(String to,
String from,
String subject,
Object body,
String contentType,
ServerSetup serverSetup)
Send the message with the given attributes and the given body using the specified SMTP settings
|
static void |
sendMimeMessage(MimeMessage mimeMessage)
Send the message using the JavaMail session defined in the message
|
static void |
sendTextEmail(String to,
String from,
String subject,
String msg,
ServerSetup setup)
Sends a text message using given server setup for SMTP.
|
static void |
sendTextEmailSecureTest(String to,
String from,
String subject,
String msg)
Sends a text message using the default test setup for SMTPS.
|
static void |
sendTextEmailTest(String to,
String from,
String subject,
String msg)
Sends a text message using the default test setup for SMTP.
|
static void |
setQuota(GreenMailUser user,
Quota quota)
Sets a quota for a users.
|
static String |
toString(Part msg) |
@Deprecated public static GreenMailUtil instance()
public static void copyStream(InputStream src, OutputStream dest) throws IOException
IOException
public static MimeMessage newMimeMessage(InputStream inputStream)
MimeMessage
from an input stream.public static MimeMessage newMimeMessage(String mailString) throws MessagingException
MimeMessage
from a stringMessagingException
public static boolean hasNonTextAttachments(Part m)
public static int getLineCount(String str)
public static String getWholeMessage(Part msg)
public static byte[] getBodyAsBytes(Part msg)
public static byte[] getHeaderAsBytes(Part part)
public static String toString(Part msg)
getWholeMessage(javax.mail.Part)
}public static String random()
public static String random(int nbrOfLetters)
public static void sendTextEmailTest(String to, String from, String subject, String msg)
to
- the to address.from
- the from address.subject
- the subject.msg
- the text message.ServerSetupTest.SMTP
public static void sendTextEmailSecureTest(String to, String from, String subject, String msg)
to
- the to address.from
- the from address.subject
- the subject.msg
- the text message.ServerSetupTest.SMTPS
public static MimeMessage createTextEmail(String to, String from, String subject, String msg, ServerSetup setup)
public static void sendTextEmail(String to, String from, String subject, String msg, ServerSetup setup)
to
- the to address.from
- the from address.subject
- the subject.msg
- the test message.setup
- the SMTP setup.public static void sendMimeMessage(MimeMessage mimeMessage)
mimeMessage
- Message to sendpublic static void sendMessageBody(String to, String from, String subject, Object body, String contentType, ServerSetup serverSetup)
to
- Destination address(es)from
- Sender addresssubject
- Message subjectbody
- Message content. May either be a MimeMultipart or another body that java mail recognizescontentType
- MIME content type of bodyserverSetup
- Server settings to use for connecting to the SMTP serverpublic static void sendAttachmentEmail(String to, String from, String subject, String msg, byte[] attachment, String contentType, String filename, String description, ServerSetup setup)
public static Session getSession(ServerSetup setup)
public static Session getSession(ServerSetup setup, Properties mailProps)
setup
- the setup type, such as ServerSetup.IMAP
mailProps
- additional mail properties.public static void setQuota(GreenMailUser user, Quota quota)
user
- the user.quota
- the quota.public static Quota[] getQuota(GreenMailUser user, String quotaRoot)
user
- the user.quotaRoot
- the quota root, eg 'INBOX.Copyright © 2006–2016 Icegreen Technologies. All rights reserved.