//Hi,
//I want to make an application that sends email; the email need to be taken from an oracle database, I had make the email code and it is working succseeful and also I made the coonection to the database in the next class which is also working successfully, but the problem I couldn't get the email from the database in this class
//This is ther class where it sends an email
import com.sun.crypto.provider.RSACipher;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.io.*;
public class conn extends CDB {
//public class sendMail {
String d_email = "sofien.fkih@gmail.com",
d_password = "",
d_host = "smtp.gmail.com",
d_port = "465",
m_to = "@gmail.com",
m_subject = "Testing",
m_text = "Hey, this is the testing email.";
public conn()
{
Properties props = new Properties();
props.put("mail.smtp.user", d_email);
props.put("mail.smtp.host", d_host);
props.put("mail.smtp.port", d_port);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
//props.put("mail.smtp.debug", "true");
props.put("mail.smtp.socketFactory.port", d_port);
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
SecurityManager security = System.getSecurityManager();
try
{
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
//session.setDebug(true);
MimeMessage msg = new MimeMessage(session);
msg.setText(m_text);
msg.setSubject(m_subject);
msg.setFrom(new InternetAddress(d_email));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(m_to));
Transport.send(msg);
}
catch (Exception mex)
{
mex.printStackTrace();
}
}
public static void main1(String[] args)
{
conn blah = new conn();
}
private class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(d_email, d_password);
}
}
}
//this is the class where it connects to database
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.io.*;
public class Main {
public static void main(String[] args) {
// conn con1 = new conn();
try
{
String host = "jdbc:oracle:thin:@ 127.0.0.1:1521:XE";
String uName = "hr";
String password="";
Connection con = DriverManager.getConnection( host, uName, password );
Statement stmt = con.createStatement( );
String SQL = "SELECT * FROM students";
ResultSet rs = stmt.executeQuery( SQL );
rs.next();
int id_col = rs.getInt("STUDENT_ID");
String first_name = rs.getString("First_Name");
String last_name = rs.getString("Last_Name");
//.out.println( id_col + " " + first_name + " " + last_name );
if (id_col==400)
{
// String mail=first_name+con1.m_to;
try{{
// conn blah = new conn();
Process p=Runtime.getRuntime().exec("cmd /c start http:www."+first_name+".com");
// those code is made to open a web page, and messages is the attribute of the table sms
// all those code were made 18,19/07/2012 by sofien fki and mohammed ahmed
}
}
catch(IOException e1){System.out.println(e1);
}
}
}
catch ( SQLException err )
{
System.out.println( err.getMessage( ) );
}
}
}