Package com.icegreen.greenmail.util
Class GreenMailUtil
java.lang.Object
com.icegreen.greenmail.util.GreenMailUtil
- Since:
- Jan 29, 2006
- Version:
- $Id: $
- Author:
- Wael Chatila
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopyStream(InputStream src, OutputStream dest) Writes the content of an input stream to an output streamstatic jakarta.mail.internet.MimeMultipartcreateMultipartWithAttachment(String msg, byte[] attachment, String contentType, String filename, String description) Create new multipart with a text part and an attachmentstatic jakarta.mail.internet.MimeMessagecreateTextEmail(String to, String from, String subject, String msg, ServerSetup setup) static StringgetAddressList(jakarta.mail.Address[] addresses) static StringgetBody(jakarta.mail.Part msg) static byte[]getBodyAsBytes(jakarta.mail.Part msg) static byte[]getHeaderAsBytes(jakarta.mail.Part part) static StringgetHeaders(jakarta.mail.Part msg) static intgetLineCount(String str) Counts the number of lines.static jakarta.mail.Quota[]getQuota(GreenMailUser user, String quotaRoot) Gets the quotas for the user.static jakarta.mail.SessiongetSession(ServerSetup setup) Gets a JavaMail Session for given server type such as IMAP and additional props for JavaMail.static jakarta.mail.SessiongetSession(ServerSetup setup, Properties mailProps) Gets a JavaMail Session for given server type such as IMAP and additional props for JavaMail.static jakarta.mail.SessiongetSession(ServerSetup setup, Properties mailProps, boolean debug) Gets a JavaMail Session for given server type such as IMAP and additional props for JavaMail.static StringgetWholeMessage(jakarta.mail.Part msg) static booleanhasNonTextAttachments(jakarta.mail.Part m) static jakarta.mail.internet.MimeMessagenewMimeMessage(InputStream inputStream) Convenience method which creates a newMimeMessagefrom an input stream.static jakarta.mail.internet.MimeMessagenewMimeMessage(String mailString) Convenience method which creates a newMimeMessagefrom a stringstatic Stringrandom()Generates a random generated password consisting of letters and digits with a length variable between 5 and 8 characters long.static Stringrandom(int nbrOfLetters) static voidsendAttachmentEmail(String to, String from, String subject, String msg, byte[] attachment, String contentType, String filename, String description, ServerSetup setup) static voidsendMessageBody(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 settingsstatic voidsendMimeMessage(jakarta.mail.internet.MimeMessage mimeMessage) Send the message using the JavaMail session defined in the messagestatic voidsendMimeMessage(jakarta.mail.internet.MimeMessage mimeMessage, String username, String password) Send the message using the JavaMail session defined in the messagestatic voidsendTextEmail(String to, String from, String subject, String msg, ServerSetup setup) Sends a text message using given server setup for SMTP.static voidsendTextEmailSecureTest(String to, String from, String subject, String msg) Sends a text message using the default test setup for SMTPS.static voidsendTextEmailTest(String to, String from, String subject, String msg) Sends a text message using the default test setup for SMTP.static voidsetQuota(GreenMailUser user, jakarta.mail.Quota quota) Sets a quota for a users.static StringtoString(jakarta.mail.Part msg)
-
Method Details
-
copyStream
Writes the content of an input stream to an output stream- Throws:
IOException- on io error.
-
newMimeMessage
Convenience method which creates a newMimeMessagefrom an input stream.- Returns:
- the created mime message.
-
newMimeMessage
Convenience method which creates a newMimeMessagefrom a string -
hasNonTextAttachments
public static boolean hasNonTextAttachments(jakarta.mail.Part m) -
getLineCount
Counts the number of lines.- Parameters:
str- the input string- Returns:
- Returns the number of lines terminated by '\n' in string
-
getBody
- Returns:
- The content part of an email (or a Part)
Note: You might have to use MimeUtility.decodeText(contentPart) on the result to decode the (possibly) quoted-printable encoded special characters.
-
getHeaders
- Returns:
- The headers of an email (or a Part)
-
getWholeMessage
- Returns:
- The both header and body for an email (or a Part)
-
getBodyAsBytes
public static byte[] getBodyAsBytes(jakarta.mail.Part msg) -
getHeaderAsBytes
public static byte[] getHeaderAsBytes(jakarta.mail.Part part) -
toString
- Returns:
- same as
getWholeMessage(jakarta.mail.Part)
-
random
Generates a random generated password consisting of letters and digits with a length variable between 5 and 8 characters long. Passwords are further optimized for displays that could potentially display the characters 1,l,I,0,O,Q in a way that a human could easily mix them up.- Returns:
- the random string.
-
random
-
sendTextEmailTest
Sends a text message using the default test setup for SMTP.- Parameters:
to- the to address.from- the from address.subject- the subject.msg- the text message.- See Also:
-
sendTextEmailSecureTest
Sends a text message using the default test setup for SMTPS.- Parameters:
to- the to address.from- the from address.subject- the subject.msg- the text message.- See Also:
-
getAddressList
-
createTextEmail
public static jakarta.mail.internet.MimeMessage createTextEmail(String to, String from, String subject, String msg, ServerSetup setup) -
sendTextEmail
public static void sendTextEmail(String to, String from, String subject, String msg, ServerSetup setup) Sends a text message using given server setup for SMTP.- Parameters:
to- the to address.from- the from address.subject- the subject.msg- the test message.setup- the SMTP setup.
-
sendMimeMessage
public static void sendMimeMessage(jakarta.mail.internet.MimeMessage mimeMessage) Send the message using the JavaMail session defined in the message- Parameters:
mimeMessage- Message to send
-
sendMimeMessage
public static void sendMimeMessage(jakarta.mail.internet.MimeMessage mimeMessage, String username, String password) Send the message using the JavaMail session defined in the message- Parameters:
mimeMessage- Message to sendusername- Username for authentication.password- Password for authentication.
-
sendMessageBody
public 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- Parameters:
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 server
-
sendAttachmentEmail
-
createMultipartWithAttachment
public static jakarta.mail.internet.MimeMultipart createMultipartWithAttachment(String msg, byte[] attachment, String contentType, String filename, String description) Create new multipart with a text part and an attachment- Parameters:
msg- Message textattachment- Attachment datacontentType- MIME content type of bodyfilename- File name of the attachmentdescription- Description of the attachment- Returns:
- New multipart
-
getSession
Gets a JavaMail Session for given server type such as IMAP and additional props for JavaMail.- Parameters:
setup- the setup type, such asServerSetup.IMAP- Returns:
- the JavaMail session.
-
getSession
Gets a JavaMail Session for given server type such as IMAP and additional props for JavaMail.- Parameters:
setup- the setup type, such asServerSetup.IMAPmailProps- additional mail properties.- Returns:
- the JavaMail session.
-
getSession
public static jakarta.mail.Session getSession(ServerSetup setup, Properties mailProps, boolean debug) Gets a JavaMail Session for given server type such as IMAP and additional props for JavaMail.- Parameters:
setup- the setup type, such asServerSetup.IMAPmailProps- additional mail properties.debug- sets JavaMail debug properties.- Returns:
- the JavaMail session.
-
setQuota
Sets a quota for a users.- Parameters:
user- the user.quota- the quota.
-
getQuota
Gets the quotas for the user.- Parameters:
user- the user.quotaRoot- the quota root, eg 'INBOX'.- Returns:
- array of current quotas, or an empty array if not set.
-