Package org.compiere.util
Class EMail
- java.lang.Object
-
- org.compiere.util.EMail
-
- All Implemented Interfaces:
Serializable
public final class EMail extends Object implements Serializable
EMail Object. Resources: http://java.sun.com/products/javamail/index.html http://java.sun.com/products/javamail/FAQ.htmlWhen 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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringEMAIL_SEND_MSGstatic StringHTML_MAIL_MARKERprotected static CLoggerlogLoggerstatic StringSENT_OKMail Sent OK Status
-
Constructor Summary
Constructors Constructor Description EMail(Properties ctx, String smtpHost, int smtpPort, boolean isSecureSmtp, String from, String to, String subject, String message, boolean html)Full ConstructorEMail(Properties ctx, String smtpHost, String from, String to, String subject, String message)Full ConstructorEMail(Properties ctx, String smtpHost, String from, String to, String subject, String message, boolean html)Full ConstructorEMail(MClient client, String from, String to, String subject, String message)Full ConstructorEMail(MClient client, String from, String to, String subject, String message, boolean html)Full Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAttachment(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 attachmentsbooleanaddBcc(String newBcc)Add BCC RecipientbooleanaddCc(String newCc)Add CC RecipientbooleanaddTo(String newTo)Add To RecipientEMailAuthenticatorcreateAuthenticator(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[]getAttachments()javax.mail.internet.InternetAddress[]getBccs()Get BCC Recipientsjavax.mail.internet.InternetAddress[]getCcs()Get CC Recipientsjavax.mail.internet.InternetAddressgetFrom()Get SenderStringgetMessageCRLF()Get MIME String Message - line ending with CRLF.StringgetMessageHTML()Get HTML MessageStringgetMessageID()Get Message ID or nullprotected javax.mail.internet.MimeMessagegetMimeMessage()Get the message directlyjavax.mail.internet.InternetAddressgetReplyTo()Get Reply ToStringgetSentMsg()Get Send Result MsgStringgetSmtpHost()Get Mail Server name or addressStringgetSubject()Get Subjectjavax.mail.internet.InternetAddressgetTo()Get Recipientjavax.mail.internet.InternetAddress[]getTos()Get TO RecipientsbooleanisSentOK()Was sending the Msg OKbooleanisValid()Is Info valid to send EMailbooleanisValid(boolean recheck)Re-Check Info if valid to send EMailstatic voidmain(String[] args)Test.Stringsend()Send Mail directvoidsetAcknoledgmentReceipt(boolean ar)voidsetForTenantSmtp(boolean forceTenantSmtp)voidsetFrom(String newFrom)Set SendervoidsetHeader(String name, String value)voidsetMessageHTML(String html)Set HTML MessagevoidsetMessageHTML(String subject, String message)Set HTML MessagevoidsetMessageText(String newMessage)Set MessagebooleansetReplyTo(String newTo)Set Reply to AddressvoidsetSmtpHost(String newSmtpHost)Set SMTP Host or addressvoidsetSubject(String newSubject)Set SubjectStringtoString()String Representationstatic booleanvalidate(String email)Validate format of an email address IDEMPIERE-1409
-
-
-
Field Detail
-
HTML_MAIL_MARKER
public static final String HTML_MAIL_MARKER
- See Also:
- Constant Field Values
-
EMAIL_SEND_MSG
public static final String EMAIL_SEND_MSG
- See Also:
- Constant Field Values
-
SENT_OK
public static final String SENT_OK
Mail Sent OK Status- See Also:
- Constant Field Values
-
log
protected static transient CLogger log
Logger
-
-
Constructor Detail
-
EMail
public EMail(MClient client, String from, String to, String subject, String message)
Full Constructor- Parameters:
client- the clientfrom- Sender's EMail addressto- Recipient EMail addresssubject- Subject of messagemessage- The message
-
EMail
public EMail(MClient client, String from, String to, String subject, String message, boolean html)
Full Constructor- 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)
Full Constructor- 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)
Full Constructor- 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)
Full Constructor- Parameters:
ctx- contextsmtpHost- The mail serversmtpPort-isSecureSmtp-from- Sender's EMail addressto- Recipient EMail addresssubject- Subject of messagemessage- The messagehtml- html email
-
-
Method Detail
-
setAcknoledgmentReceipt
public void setAcknoledgmentReceipt(boolean ar)
-
send
public String send()
Send Mail direct- Returns:
- OK or error message
-
getSentMsg
public String 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
public String getMessageID()
Get Message ID or null- Returns:
- Message ID e.g. <20030130004739.15377.qmail@web13506.mail.yahoo.com> <25699763.1043887247538.JavaMail.jjanke@main>
-
createAuthenticator
public EMailAuthenticator createAuthenticator(String username, String password)
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
public void setFrom(String newFrom)
Set Sender- Parameters:
newFrom- Sender's email address
-
addTo
public boolean addTo(String newTo)
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
public boolean addCc(String newCc)
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
public boolean addBcc(String newBcc)
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
public boolean setReplyTo(String newTo)
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
public void setSubject(String newSubject)
Set Subject- Parameters:
newSubject- Subject
-
getSubject
public String getSubject()
Get Subject- Returns:
- subject
-
setMessageText
public void setMessageText(String newMessage)
Set Message- Parameters:
newMessage- message
-
getMessageCRLF
public String getMessageCRLF()
Get MIME String Message - line ending with CRLF.- Returns:
- message
-
setMessageHTML
public void setMessageHTML(String html)
Set HTML Message- Parameters:
html- message
-
setMessageHTML
public void setMessageHTML(String subject, String message)
Set HTML Message- Parameters:
subject- subject repeated in message as H2message- message
-
getMessageHTML
public String getMessageHTML()
Get HTML Message- Returns:
- message
-
addAttachment
public void addAttachment(File file)
Add file Attachment- Parameters:
file- file to attach
-
addAttachments
public void addAttachments(Collection<File> files)
Add a collection of attachments- Parameters:
files- collection of files
-
addAttachment
public void addAttachment(URI url)
Add url based file Attachment- Parameters:
url- url content to attach
-
addAttachment
public void addAttachment(byte[] data, String type, String name)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
public void setSmtpHost(String newSmtpHost)
Set SMTP Host or address- Parameters:
newSmtpHost- Mail server
-
getSmtpHost
public String 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
public Object[] getAttachments()
- Returns:
- attachments array or empty array. This method will never return null.
-
toString
public String toString()
String Representation
-
validate
public static boolean validate(String email)
Validate format of an email address IDEMPIERE-1409- Returns:
- true if email has proper format
-
main
public static void main(String[] args)
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
-
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)
-
-