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 String
EMAIL_SEND_MSG
static String
HTML_MAIL_MARKER
protected static CLogger
log
Loggerstatic String
SENT_OK
Mail 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 void
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
addBcc(String newBcc)
Add BCC Recipientboolean
addCc(String newCc)
Add CC Recipientboolean
addTo(String newTo)
Add To RecipientEMailAuthenticator
createAuthenticator(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[]
getAttachments()
javax.mail.internet.InternetAddress[]
getBccs()
Get BCC Recipientsjavax.mail.internet.InternetAddress[]
getCcs()
Get CC Recipientsjavax.mail.internet.InternetAddress
getFrom()
Get SenderString
getMessageCRLF()
Get MIME String Message - line ending with CRLF.String
getMessageHTML()
Get HTML MessageString
getMessageID()
Get Message ID or nullprotected javax.mail.internet.MimeMessage
getMimeMessage()
Get the message directlyjavax.mail.internet.InternetAddress
getReplyTo()
Get Reply ToString
getSentMsg()
Get Send Result MsgString
getSmtpHost()
Get Mail Server name or addressString
getSubject()
Get 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
main(String[] args)
Test.String
send()
Send Mail directvoid
setAcknoledgmentReceipt(boolean ar)
void
setForTenantSmtp(boolean forceTenantSmtp)
void
setFrom(String newFrom)
Set Sendervoid
setHeader(String name, String value)
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 SubjectString
toString()
String Representationstatic boolean
validate(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)
-
-