Package org.compiere.util
Class EMail
java.lang.Object
org.compiere.util.EMail
- All Implemented Interfaces:
Serializable
EMail delivery and receive support for iDempiere
http://java.sun.com/products/javamail/index.html
http://java.sun.com/products/javamail/FAQ.html
Resources:
When I try to send a message, I get javax.mail.SendFailedException:
550 Unable to relay for my-address
This is an error reply from your SMTP mail server. It indicates that
your mail server is not configured to allow you to send mail through it.
- Version:
- $Id: EMail.java,v 1.4 2006/07/30 00:54:35 jjanke Exp $
- Author:
- Jorg Janke, Michael Judd BF [ 2736995 ] - toURL() in java.io.File has been depreciated
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAttachment(byte[] data, String type, String name) Add attachment.voidaddAttachment(File file) Add file AttachmentvoidaddAttachment(URI url) Add url based file AttachmentvoidaddAttachment(javax.activation.DataSource dataSource) Add arbitrary AttachmentvoidaddAttachments(Collection<File> files) Add a collection of attachmentsbooleanAdd BCC RecipientbooleanAdd CC RecipientbooleanAdd To RecipientcreateAuthenticator(String username, String password) Create Authenticator for Userstatic javax.mail.internet.InternetAddresscreateInternetAddress(String email) Create an internet address with personal if the email address is formatted as "Personal" Object[]Get attachmentsjavax.mail.internet.InternetAddress[]getBccs()Get BCC Recipientsjavax.mail.internet.InternetAddress[]getCcs()Get CC Recipientsjavax.mail.internet.InternetAddressgetFrom()Get SenderGet MIME String Message - line ending with CRLF.Get HTML MessageGet Message ID or nullprotected javax.mail.internet.MimeMessageGet the messagejavax.mail.internet.InternetAddressGet Reply ToGet Send Result MsgGet Mail Server name or addressGet Subjectjavax.mail.internet.InternetAddressgetTo()Get Recipientjavax.mail.internet.InternetAddress[]getTos()Get TO RecipientsbooleanisSentOK()Is send successbooleanisValid()Is Info valid to send EMailbooleanisValid(boolean recheck) Re-Check Info is valid to send EMailsend()Send Mailsend(boolean throwException) Send MailsendEx()Send MailvoidsetAcknoledgmentReceipt(boolean ar) Set acknowledgement for receipt (Disposition-Notification-To)voidsetForTenantSmtp(boolean forceTenantSmtp) Set is force the user of tenant SMTP configurationvoidSet SendervoidSet additional headersvoidsetMessageHTML(String html) Set HTML MessagevoidsetMessageHTML(String subject, String message) Set HTML MessagevoidsetMessageText(String newMessage) Set Message BodybooleansetReplyTo(String newTo) Set Reply to AddressvoidsetSmtpHost(String newSmtpHost) Set SMTP Host or addressvoidsetSubject(String newSubject) Set SubjecttoString()String Representationstatic booleanValidate format of an email address IDEMPIERE-1409
-
Field Details
-
HTML_MAIL_MARKER
HTML mail marker- See Also:
-
EMAIL_SEND_MSG
log last email send error message in context- See Also:
-
SENT_OK
Mail Sent OK Status- See Also:
-
log
Logger
-
-
Constructor Details
-
EMail
- Parameters:
client- the clientfrom- Sender's EMail addressto- Recipient EMail addresssubject- Subject of messagemessage- The message
-
EMail
- Parameters:
client- the clientfrom- Sender's EMail addressto- Recipient EMail addresssubject- Subject of messagemessage- The messagehtml-
-
EMail
public EMail(Properties ctx, String smtpHost, String from, String to, String subject, String message) - Parameters:
ctx- contextsmtpHost- The mail serverfrom- Sender's EMail addressto- Recipient EMail addresssubject- Subject of messagemessage- The message
-
EMail
public EMail(Properties ctx, String smtpHost, String from, String to, String subject, String message, boolean html) - Parameters:
ctx- contextsmtpHost- The mail serverfrom- Sender's EMail addressto- Recipient EMail addresssubject- Subject of messagemessage- The messagehtml- html email
-
EMail
public EMail(Properties ctx, String smtpHost, int smtpPort, boolean isSecureSmtp, String from, String to, String subject, String message, boolean html) - Parameters:
ctx- contextsmtpHost- The mail serversmtpPort-isSecureSmtp-from- Sender's EMail addressto- Recipient EMail addresssubject- Subject of messagemessage- The messagehtml- html email
-
-
Method Details
-
setAcknoledgmentReceipt
public void setAcknoledgmentReceipt(boolean ar) Set acknowledgement for receipt (Disposition-Notification-To)- Parameters:
ar-
-
send
Send Mail- Returns:
- OK or error message
-
sendEx
Send Mail- Returns:
- OK or error message
- Throws:
Exception
-
send
Send Mail- Returns:
- OK or error message
- Throws:
Exception
-
getSentMsg
Get Send Result Msg- Returns:
- msg
-
isSentOK
public boolean isSentOK()Is send success- Returns:
- msg == SENT_OK
-
getMimeMessage
protected javax.mail.internet.MimeMessage getMimeMessage()Get the message- Returns:
- mail message
-
getMessageID
Get Message ID or null- Returns:
- Message ID e.g. <20030130004739.15377.qmail@web13506.mail.yahoo.com> <25699763.1043887247538.JavaMail.jjanke@main>
-
createAuthenticator
Create Authenticator for User- Parameters:
username- user namepassword- user password- Returns:
- Authenticator or null
-
getFrom
public javax.mail.internet.InternetAddress getFrom()Get Sender- Returns:
- Sender's internet address
-
setFrom
Set Sender- Parameters:
newFrom- Sender's email address
-
addTo
Add To Recipient- Parameters:
newTo- Recipient's email address- Returns:
- true if valid
-
getTo
public javax.mail.internet.InternetAddress getTo()Get Recipient- Returns:
- Recipient's internet address
-
getTos
public javax.mail.internet.InternetAddress[] getTos()Get TO Recipients- Returns:
- Recipient's internet address
-
addCc
Add CC Recipient- Parameters:
newCc- EMail cc Recipient- Returns:
- true if valid
-
getCcs
public javax.mail.internet.InternetAddress[] getCcs()Get CC Recipients- Returns:
- Recipient's internet address
-
addBcc
Add BCC Recipient- Parameters:
newBcc- EMail cc Recipient- Returns:
- true if valid
-
getBccs
public javax.mail.internet.InternetAddress[] getBccs()Get BCC Recipients- Returns:
- Recipient's internet address
-
setReplyTo
Set Reply to Address- Parameters:
newTo- email address- Returns:
- true if valid
-
getReplyTo
public javax.mail.internet.InternetAddress getReplyTo()Get Reply To- Returns:
- Reply To internet address
-
setSubject
Set Subject- Parameters:
newSubject- Subject
-
getSubject
Get Subject- Returns:
- subject
-
setMessageText
Set Message Body- Parameters:
newMessage- message
-
getMessageCRLF
Get MIME String Message - line ending with CRLF.- Returns:
- message
-
setMessageHTML
Set HTML Message- Parameters:
html- message
-
setMessageHTML
Set HTML Message- Parameters:
subject- subject repeated in message as H2message- message
-
getMessageHTML
Get HTML Message- Returns:
- message
-
addAttachment
Add file Attachment- Parameters:
file- file to attach
-
addAttachments
Add a collection of attachments- Parameters:
files- collection of files
-
addAttachment
Add url based file Attachment- Parameters:
url- url content to attach
-
addAttachment
Add attachment. (converted to ByteArrayDataSource)- Parameters:
data- datatype- MIME typename- name of attachment
-
addAttachment
public void addAttachment(javax.activation.DataSource dataSource) Add arbitrary Attachment- Parameters:
dataSource- content to attach
-
setSmtpHost
Set SMTP Host or address- Parameters:
newSmtpHost- Mail server
-
getSmtpHost
Get Mail Server name or address- Returns:
- mail server
-
isValid
public boolean isValid()Is Info valid to send EMail- Returns:
- true if email is valid and can be sent
-
isValid
public boolean isValid(boolean recheck) Re-Check Info is valid to send EMail- Parameters:
recheck- if true check main variables- Returns:
- true if email is valid and can be sent
-
getAttachments
Get attachments- Returns:
- attachments array or empty array. This method will never return null.
-
toString
String Representation -
validate
Validate format of an email address IDEMPIERE-1409- Returns:
- true if email has proper format
-
setHeader
Set additional headers- Parameters:
name-value-
-
createInternetAddress
public static javax.mail.internet.InternetAddress createInternetAddress(String email) throws Exception Create an internet address with personal if the email address is formatted as "Personal" - Parameters:
email-- Returns:
- internet address with personal if defined
- Throws:
Exception
-
setForTenantSmtp
public void setForTenantSmtp(boolean forceTenantSmtp) Set is force the user of tenant SMTP configuration- Parameters:
forceTenantSmtp-
-