Adempiere 3.5.2a

org.compiere.util
Class EMail

java.lang.Object
  extended by 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.html

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
See Also:
Serialized Form

Field Summary
static String HTML_MAIL_MARKER
           
protected static CLogger log
          Logger
static String SENT_OK
          Mail Sent OK Status
 
Constructor Summary
EMail(MClient client, String from, String to, String subject, String message)
          Full Constructor
EMail(MClient client, String from, String to, String subject, String message, boolean html)
          Full Constructor
EMail(Properties ctx, String smtpHost, String from, String to, String subject, String message)
          Full Constructor
EMail(Properties ctx, String smtpHost, String from, String to, String subject, String message, boolean html)
          Full Constructor
 
Method Summary
 void addAttachment(byte[] data, String type, String name)
          Add attachment.
 void addAttachment(DataSource dataSource)
          Add arbitary Attachment
 void addAttachment(File file)
          Add file Attachment
 void addAttachment(URL url)
          Add url based file Attachment
 void addAttachments(Collection<File> files)
          Add a collection of attachments
 boolean addBcc(String newBcc)
          Add BCC Recipient
 boolean addCc(String newCc)
          Add CC Recipient
 boolean addTo(String newTo)
          Add To Recipient
 EMailAuthenticator createAuthenticator(String username, String password)
          Create Authenticator for User
 InternetAddress[] getBccs()
          Get BCC Recipients
 InternetAddress[] getCcs()
          Get CC Recipients
 InternetAddress getFrom()
          Get Sender
 String getMessageCRLF()
          Get MIME String Message - line ending with CRLF.
 String getMessageHTML()
          Get HTML Message
 String getMessageID()
          Get Message ID or null
protected  MimeMessage getMimeMessage()
          Get the message directly
 InternetAddress getReplyTo()
          Get Reply To
 String getSentMsg()
          Get Send Result Msg
 String getSmtpHost()
          Get Mail Server name or address
 String getSubject()
          Get Subject
 InternetAddress getTo()
          Get Recipient
 InternetAddress[] getTos()
          Get TO Recipients
 boolean isSentOK()
          Was sending the Msg OK
 boolean isValid()
          Is Info valid to send EMail
 boolean isValid(boolean recheck)
          Re-Check Info if valid to send EMail
static void main(String[] args)
          Test.
 String send()
          Send Mail direct
 void setFrom(String newFrom)
          Set Sender
 void setMessageHTML(String html)
          Set HTML Message
 void setMessageHTML(String subject, String message)
          Set HTML Message
 void setMessageText(String newMessage)
          Set Message
 boolean setReplyTo(String newTo)
          Set Reply to Address
 void setSmtpHost(String newSmtpHost)
          Set SMTP Host or address
 void setSubject(String newSubject)
          Set Subject
 String toString()
          String Representation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HTML_MAIL_MARKER

public static final String HTML_MAIL_MARKER
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 CLogger log
Logger

Constructor Detail

EMail

public EMail(MClient client,
             String from,
             String to,
             String subject,
             String message)
Full Constructor

Parameters:
client - the client
from - Sender's EMail address
to - Recipient EMail address
subject - Subject of message
message - The message

EMail

public EMail(MClient client,
             String from,
             String to,
             String subject,
             String message,
             boolean html)
Full Constructor

Parameters:
client - the client
from - Sender's EMail address
to - Recipient EMail address
subject - Subject of message
message - The message
html -

EMail

public EMail(Properties ctx,
             String smtpHost,
             String from,
             String to,
             String subject,
             String message)
Full Constructor

Parameters:
ctx - context
smtpHost - The mail server
from - Sender's EMail address
to - Recipient EMail address
subject - Subject of message
message - The message

EMail

public EMail(Properties ctx,
             String smtpHost,
             String from,
             String to,
             String subject,
             String message,
             boolean html)
Full Constructor

Parameters:
ctx - context
smtpHost - The mail server
from - Sender's EMail address
to - Recipient EMail address
subject - Subject of message
message - The message
html - html email
Method Detail

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 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 name
password - user password
Returns:
Authenticator or null

getFrom

public 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 InternetAddress getTo()
Get Recipient

Returns:
Recipient's internet address

getTos

public 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 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 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 InternetAddress getReplyTo()
Get Reply To

Returns:
Reoly 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 H2
message - 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(URL 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 - data
type - MIME type
name - name of attachment

addAttachment

public void addAttachment(DataSource dataSource)
Add arbitary 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

toString

public String toString()
String Representation

Overrides:
toString in class Object
Returns:
info

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

Adempiere 3.5.2a

Adempiere® is a registered trademark of ADempiere Business Inc. ©2004-2008 HumanFlash.com All rights reserved.