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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttachment
(byte[] data, String type, String name) Add attachment.void
addAttachment
(File file) Add file Attachmentvoid
addAttachment
(URI url) Add url based file Attachmentvoid
addAttachment
(javax.activation.DataSource dataSource) Add arbitrary Attachmentvoid
addAttachments
(Collection<File> files) Add a collection of attachmentsboolean
Add BCC Recipientboolean
Add CC Recipientboolean
Add To RecipientcreateAuthenticator
(String username, String password) Create Authenticator for Userstatic javax.mail.internet.InternetAddress
createInternetAddress
(String email) Create an internet address with personal if the email address is formatted as "Personal" Object[]
javax.mail.internet.InternetAddress[]
getBccs()
Get BCC Recipientsjavax.mail.internet.InternetAddress[]
getCcs()
Get CC Recipientsjavax.mail.internet.InternetAddress
getFrom()
Get SenderGet MIME String Message - line ending with CRLF.Get HTML MessageGet Message ID or nullprotected javax.mail.internet.MimeMessage
Get the message directlyjavax.mail.internet.InternetAddress
Get Reply ToGet Send Result MsgGet Mail Server name or addressGet Subjectjavax.mail.internet.InternetAddress
getTo()
Get Recipientjavax.mail.internet.InternetAddress[]
getTos()
Get TO Recipientsboolean
isSentOK()
Was sending the Msg OKboolean
isValid()
Is Info valid to send EMailboolean
isValid
(boolean recheck) Re-Check Info if valid to send EMailstatic void
Test.send()
Send Mail directsend
(boolean throwException) Send Mail directsendEx()
Send Mail directvoid
setAcknoledgmentReceipt
(boolean ar) void
setForTenantSmtp
(boolean forceTenantSmtp) void
Set Sendervoid
void
setMessageHTML
(String html) Set HTML Messagevoid
setMessageHTML
(String subject, String message) Set HTML Messagevoid
setMessageText
(String newMessage) Set Messageboolean
setReplyTo
(String newTo) Set Reply to Addressvoid
setSmtpHost
(String newSmtpHost) Set SMTP Host or addressvoid
setSubject
(String newSubject) Set SubjecttoString()
String Representationstatic boolean
Validate format of an email address IDEMPIERE-1409
-
Field Details
-
HTML_MAIL_MARKER
- See Also:
-
EMAIL_SEND_MSG
- 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) -
send
Send Mail direct- Returns:
- OK or error message
-
sendEx
Send Mail direct- Returns:
- OK or error message
- Throws:
Exception
-
send
Send Mail direct- Returns:
- OK or error message
- Throws:
Exception
-
getSentMsg
Get Send Result Msg- Returns:
- msg
-
isSentOK
public boolean isSentOK()Was sending the Msg OK- Returns:
- msg == OK
-
getMimeMessage
protected javax.mail.internet.MimeMessage getMimeMessage()Get the message directly- 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- 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 if valid to send EMail- Parameters:
recheck
- if true check main variables- Returns:
- true if email is valid and can be sent
-
getAttachments
- 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
-
main
Test. java -cp CTools.jar;CClient.jar org.compiere.util.EMail main info@adempiere.org jjanke@adempiere.org "My Subject" "My Message" -- If you get SendFailedException: 550 5.7.1 Unable to relay for .. Check: - Does the SMTP server allow you to relay (Exchange: SMTP server - Access) - Did you authenticate (setEmailUser)- Parameters:
args
- Array of arguments
-
setHeader
-
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)
-