Class GreenMailUtil
java.lang.Object
com.icegreen.greenmail.util.GreenMailUtil
- Since:
- Jan 29, 2006
- Author:
- Wael Chatila
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopyStream(InputStream src, OutputStream dest) Writes the content of an input stream to an output streamstatic MimeMultipartcreateMultipartWithAttachment(String msg, byte[] attachment, String contentType, String filename, String description) Create new multipart with a text part and an attachmentstatic MimeMessagecreateTextEmail(String to, String from, String subject, String msg, ServerSetup setup) static StringgetAddressList(Address[] addresses) static Stringstatic byte[]getBodyAsBytes(Part msg) static byte[]getHeaderAsBytes(Part part) static StringgetHeaders(Part msg) static intgetLineCount(String str) Counts the number of lines.static Quota[]getQuota(GreenMailUser user, String quotaRoot) Gets the quotas for the user.static SessiongetSession(ServerSetup setup) Gets a JavaMail Session for given server type such as IMAP and additional props for JavaMail.static SessiongetSession(ServerSetup setup, Properties mailProps) Gets a JavaMail Session for given server type such as IMAP and additional props for JavaMail.static 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(Part msg) static booleanstatic MimeMessagenewMimeMessage(InputStream inputStream) Convenience method which creates a newMimeMessagefrom an input stream.static 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(MimeMessage mimeMessage) Send the message using the JavaMail session defined in the messagestatic voidsendMimeMessage(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, Quota quota) Sets a quota for a users.static String
-
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
-
getLineCount
Counts the number of lines.- Parameters:
str- the input string- Returns:
- Returns the number of lines terminated by '\n' in string
-
getBody
-
getHeaders
-
getWholeMessage
-
getBodyAsBytes
-
getHeaderAsBytes
-
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
-
sendTextEmailSecureTest
-
getAddressList
-
createTextEmail
public static 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
Send the message using the JavaMail session defined in the message- Parameters:
mimeMessage- Message to send
-
sendMimeMessage
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 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
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.
-