The javax.mail.Transport object is used for sending e-mail messages. It is an abstract class that represents the SMTP protocol implementation.
You get a Transport object by using the getTransport("smtp") method of the session object.
There are two ways to specify the connection settings for the respective SMTP server:
● Using the respective service property
You can specify an SMTP server to be used for all sending operations by setting the correct value for the Smtp property of the JavaMail Client Service. Its value represents the server name or address (for example: smtp.my.server).
You can set the value of this property using the NetWeaver Administrator.
More information: Java System Properties.
● Using the connect method of the Transport object
The connect method has variants that allow you to specify the server host, port and user account, if necessary.
If you do not specify a port for connection, the default SMTP port (25) is used.
To send an e-mail message to a specified address, use the send(Message) method of the Transport object. As a prerequisite, you need to have a ready Messageobject representing the message content and additional attributes.
More information: Creating E-Mail Messages.
The following source code sample illustrates getting the SMTP transport implementation and sending a ready e-mail message.
tr = ses.getTransport("smtp"); tr.send(message); |