public class SmtpService
extends java.lang.Object
Example
... SmtpMessage msg = new SmtpMessage(); SmtpService service = new SmtpService(); service.setMailhost("mailhost"); service.setSenderDomain("mydomain"); service.init(jsmsProperties); msg.addRecipient("user1@domain1.com"); msg.addRecipient("user2@domain2.com", Recipient.RT_CC); msg.addRecipient("myself@mydomain",Recipient.RT_BCC); msg.setSubject("Business lunch"); msg.setMessage("Business lunch today at the Restaurant 'Chez Max'"); try { service.sendMessage(msg); System.out.println("Message sent successfuly, ID is "+msg.getMessageId()); } catch( MessageException me ) { System.err.println("Message could not be sent: "+me.getMessage()); }
SmtpMessage
Constructor and Description |
---|
SmtpService()
Create a new Smtp service.
|
SmtpService(java.io.File conf)
Create a new Smtp Service.
|
SmtpService(java.util.Properties conf)
Create a new Smtp Service.
|
SmtpService(java.lang.String mailhost,
java.lang.String maildomain)
Create a new Smtp service.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getDefaultSender()
Get the default sender.
|
java.lang.String |
getDefaultSubject()
Get the default subject.
|
java.lang.String |
getMailhost()
Get the address of the smtp server.
|
int |
getMailport()
Get the port where the smtp-server is listening.
|
java.lang.String |
getSenderDomain()
Get the sender domain name
|
void |
init()
Initialize this service.
|
void |
init(java.io.File file)
Initialize the SMTP Service.
|
void |
init(java.util.Properties p)
Initialize the SMTP Service.
|
static void |
main(java.lang.String[] args)
Send a Internet mail message from the command line.
|
void |
sendMessage(Message message)
Sends the message via mail.
|
void |
sendMessage(SmtpMessage message)
Send a SmtpMessage to one or multiple recipients.
|
void |
setDefaultSender(java.lang.String sender)
Set the default sender address
|
void |
setDefaultSubject(java.lang.String subject)
Set the default subject.
|
void |
setMailhost(java.lang.String mailhost)
Set the address of the smtp-server.
|
void |
setMailport(int mailport)
Set the port of the smtp-server
|
void |
setSenderDomain(java.lang.String domain)
Set the sender domain.
|
public SmtpService()
public SmtpService(java.lang.String mailhost, java.lang.String maildomain)
mailhost
- the Smtp Server to use for sending mails.maildomain
- the senders domain name.public SmtpService(java.util.Properties conf)
smtp.host | the Smtp server to use for sending mail |
---|---|
smtp.domain | the senders domain name. |
smtp.subject | the default subject that will be used when sending messages that have no (null) subject |
smtp.sender | the default sender address that will be used when sending messages that have no sender |
conf
- configuration datapublic SmtpService(java.io.File conf) throws java.io.FileNotFoundException, java.io.IOException
java.io.FileNotFoundException
java.io.IOException
SmtpService(Properties conf)
public void init() throws MessageException
init(Properties)
.
The location of the jSMS properties can be specified by defining the System
property "jsms.conf". If the System property is not set, jSMS uses the
value "jsms.conf" as default. The System property be set by
e.g. passing it as parameter to the Java VM (java -Djsms.conf=...
).
If the jsms.conf location is non-absolute, the method tries to locate it
by...
Example values for jsms.conf are:
MessageException
public void init(java.io.File file) throws java.io.FileNotFoundException, java.io.IOException
java.io.FileNotFoundException
java.io.IOException
public void init(java.util.Properties p)
public java.lang.String getMailhost()
public void setMailhost(java.lang.String mailhost)
mailhost
- the mailhost to use for delivering mailpublic void setSenderDomain(java.lang.String domain)
domain
- the domain namepublic java.lang.String getSenderDomain()
public int getMailport()
public void setMailport(int mailport)
mailport
- public java.lang.String getDefaultSender()
public void setDefaultSender(java.lang.String sender)
sender
- getDefaultSender()
public java.lang.String getDefaultSubject()
public void setDefaultSubject(java.lang.String subject)
subject
- getDefaultSubject()
public void sendMessage(SmtpMessage message) throws MessageException
message
- the message to sendMessageException
- if the message could not be sent or the
service has not been initialized properlypublic void sendMessage(Message message) throws MessageException
message
- the message to sendMessageException
- if the message could not be sentsendMessage(SmtpMessage)
public static void main(java.lang.String[] args)
Usage: SmtpService <-c configfile> [-V] [-h host] [-d domain] [-s subject] [-f sender] [-m file]Options: -c configuration file containing at least a valid jSMS license key -V display version information -h Smtp Host to use -s Subject -d Sender Domain -m read message from file -f Your mail adress
If you do not specify a file (-m file), the mail message will be read from standard input (STDIN).
object XP, Inc. © 2000-2013. All rights reserved object XP