• Post Reply Bookmark Topic Watch Topic
  • New Topic

sun.net.smtp with tomcat  RSS feed

 
Jack McCarthy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to send an email to confirm an order. The project is in JSP and runs on my local host using tomcat. I'm trying to send the mail from my college account (00721883@wit.ie, with the smtp of gwstudent@wit.ie) but it never sned anything here's a copy of the code:
<!---------------------- Initialise database + get packages ------------------------------>
<%@ page import="sun.net.smtp.SmtpClient, java.io.*, java.sql.*" %>
<%
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

Connection Conn = DriverManager.getConnection("jdbc racle:thin:@witnt07.wit.ie:1521 rawit","27csd03", "27csd03");
//Creating the Connection Statement
Statement stmt = Conn.createStatement();
%>
<!-------------------------------------------------------------------------------------------->
<%
/********** This will Retrieve & store the size AND qty for each itemthe user selected**************/
String[] selectedItems = new String[itemCount*2];//hold the barcode AND qty for each item
int SIindex = 0;//will act as the index for SelectedItems array here and later on
/**************** Get & store the kid(s) details - size & qty *******************/
//for every item, we will assign its size and qty to an array, so we can acess it later ie. Size1 or Qty2
for(int i = 1; i <= itemCount; i++)
{
StringBuffer barcode = new StringBuffer(10);// => barcode1515
StringBuffer qty = new StringBuffer(11);//orderQty999
barcode.append("barcode");//each item on the last page had a barcode with name barcodeX where X =1,2,3...
qty.append("orderQty");//qty is same principle as size
String num = Integer.toString(i);//get the value for X to append to the string size or qty
barcode.append(num);
qty.append(num);
String theBarcode = barcode.toString();//assign string 'theBarcode' the value Barcode1,
String theQty = qty.toString();
selectedItems[SIindex] = request.getParameter(theBarcode);//get values from previous page and store in arrays
SIindex++;
selectedItems[SIindex] = request.getParameter(theQty);
SIindex++;
}
/**************************************************************************************************/
/*************** Get email for this supplier **************************/
ResultSet EmailRS = stmt.executeQuery("select email from supplier where CoName = '" + session.getAttribute("theSupplier") + "' ");
int numCols = EmailRS.getMetaData().getColumnCount();
String email = "Suppliers Email Address";
while ( EmailRS.next() )// specific school from a specific supplier
{
email = EmailRS.getString(1).trim();
}
/****************************************************************************************************/
/************ Setup the parameters to send the email *************************/
String from = "ebodet-cais4@computing.dcu.ie";
String to = email;
double total = 0;
try
{
SmtpClient client = new SmtpClient("mail.computing.dcu.ie");
client.from(from);
client.to(to);
PrintStream message = client.startMessage();
message.println("To: " + to);
message.println("Subject: O`Farrell School-Wear Order");
message.print("Barcode\t | Qty\t | School\t\t | Item\t\t | Size\t | Price\t | Subtotal");//print headers
message.print("\n-------------------------------------------------------------------------------------------------------------------------------------------");
for(int i = 0; i < SIindex; i = i+2)//write the details to the email
{
int qty = Integer.parseInt(selectedItems[i+1]);
/*********** Get + print remaining item details **************************/
if(qty > 0)//only want to display items that were selected
{
ResultSet DetailsRS = stmt.executeQuery("select SchoolName, Item, ItemSize, SupplierPrice, (SupplierPrice * " + qty + ") from stock where barcode = " + selectedItems[i] + " ");
numCols = DetailsRS.getMetaData().getColumnCount();
String[] remainingDetails = new String[5];
while ( DetailsRS.next() )// specific school from a specific supplier
{
for (int k=1; k<=numCols; k++)
{
remainingDetails[k-1] = DetailsRS.getString(k).trim();
}
}
total = total + Double.parseDouble(remainingDetails[4]);
/****************************************************************************************************/
message.print("\n" + selectedItems[i] + "\t | ");//print barcode
message.print(selectedItems[i+1] + "\t | ");//print qty
message.print(remainingDetails[0] + "\t | ");//print schoolName
if (remainingDetails[1].length() <= 8)//make sure that the item names are in right columns
{
message.print(remainingDetails[1] + "\t\t | ");//print Item for item with small string length
}
else
{
message.print(remainingDetails[1] + "\t | ");//print Item for item with long string length
}
message.print(remainingDetails[2] + "\t | ");//print ItemSize
message.print(remainingDetails[3] + "\t | ");//print SupplierPrice
message.print(remainingDetails[4]);//print Price*Qty
}
}
message.println("\n-------------------------------------------------------------------------------------------------------------------------------------------");
message.print("\t\t\t\t\t\t\t\t | " + total);//print total
/*********************************************************************************************************/
client.closeServer();
}
catch (IOException e)
{
System.out.println("ERROR SENDING EMAIL:"+e);
}
/**************************************************************************************************/
%>

I know when i normally logon on to the wit.ie email i have to provid a password, which this code does not ask for. I could care less where the code is sent from i just want it to send to the email addresss thats passed to it. Any help wud be appreciated. thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even though you are running this code in a JSP (way too much code for a JSP if you ask me) the question really has nothing to do with JSP, so I'm moving this along to the Other Java APIs forum.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!