Database Reference
In-Depth Information
We build the recipient e-mail address from the user's cell phone number, smsNo , and the SMS
gateway address for his carrier, smsURL .
Listing 9-26. Distribute the Code to SMS, distribToSMS()
private static final int distribToSMS( String twoFactorAuth, String smsNo,
String smsURL )
{
int distribCode = 0 ;
Statement stmt = null;
try {
stmt = conn.createStatement();
stmt.executeUpdate( " ALTER SESSION SET SMTP_OUT_SERVER = '" +
smtpHost + "'" );
stmt.executeUpdate( " CALL UTL_MAIL.SEND ( 'response@" +
comDomain + "', '" + smsNo + "@" + smsURL +
"', '', '', 'Response','" + twoFactorAuth + "' )" );
distribCode += USE_SMS ;
} catch ( Exception x ) {
} finally {
try {
if( stmt != null ) stmt.close();
} catch( Exception y ) {}
}
return distribCode ;
}
As an example, this message would look like the following.
From: response@org.com
To: 8005551212@txt.att.net
Subject: Response
1234-5678-9012
Notice also in this message that we are using the try / catch / finally block to close the statement. We
set a method member, distribCode , to 0 at the outset. If we succeed in sending the code to the cell
phone, we add the value of the USE_SMS constant to distribCode . And finally we return distribCode .
Distributing the Code to Pager URL
The distribToPagerURL() method has many similarities to distribToSMS() , which we just discussed.
The main difference is that we are not using an Oracle package to send e-mail but are using a pure Java
URL class to read a web page. See Listing 9-27. In actuality, we are not concerned with what a browser
would see when going to this web page. The entry form that a user would see in his browser window is
never loaded. It is bypassed because we are submitting the input fields data as part of the URL address.
We are using what is called the GET method to pass values to the web server on the URL line. Our URL
will resemble this:
www.org.com/servlet/textpage.PageServlet?PAGERID=12345&MESSAGE=1234-5678-9012
 
Search WWH ::




Custom Search