Here I Come with the Java Code Which can Be used to mail other persons.. Earlier i had written about Oracle Procedure which can send mails. The Java Code which I have made is quite simple and can be easily understood. The code can be extended to incorporate features such as Attaching files. All One has to have is an SMTP host which will send the mail.
People can look for JavaDoc for more Details..
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class SendMailTry {
public void sendMessage() throws AddressException, MessagingException {
Properties props = new Properties();
props.put("mail.smtp.host", "SMTP Host Server Name Here");
Session session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("rakesh_xav@rediffmail.com"));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress("rakesh_xav@yahoo.co.in"));
msg.setSubject("Testing....");
msg.setSentDate(new Date());
msg.setText("Hi All,\nTrying for a Test Mail\n\nRegards,\nRakesh");
Transport.send(msg);
}
public static void main(String[] args) {
SendMailTry sendMail = new SendMailTry();
try {
sendMail.sendMessage();
} catch (Exception e) {
e.printStackTrace();
}
}
}
I am a polyglot programmer, who loves to design & architect solutions and have an opinion on technology. This blog is my space where I share my ideas on technology. They are my ramblings on Tech space in Java & JVM based Languages
Monday, April 03, 2006
Thursday, March 30, 2006
AJAX Code... Mystery Behind it...
Spent another day trying to Demystify AJAX (Asynchronous JAvaScript XML ) code..... Without any Success
Monday, March 27, 2006
Java 5 || Java 1.5
Java 5 has come up with many changes. I Went for A KSS today. Java 5, this is the new way of calling the new java releases now, earlier we used to call it java 1.2 & java 1.4 etc.
The language has come up with many good changes; Most of the Changes which i could understand were fabulous.
Some of the Changes in Java 5 are:-
1. Boxing & UnBoxing
eg..
Integer iobj = 10;
int i = iobj;
2. Enhanced For Loops
eg..
for(int i=0;i < nums.length;i++)
out.println(nums[i]);
for(int i : nums )
out.println(nums[i]);
3. Enumerations: enum
4. Static Import: Think about using random instead of Math.random();
5. Varargs : Variable length Arguments
6. Formatted IO : Functions like printf()added.
7. Generics: Something related of template in C++. Generic Classes & Methods..
8. MetaData : It is more advanced than javadoc, better support for Implementation Team
9. N/w & security: some new Classes for SSL support
10. Changes in JVM, related to Thread, about different states of Thread.
Well there are many changes these are few to name…
The language has come up with many good changes; Most of the Changes which i could understand were fabulous.
Some of the Changes in Java 5 are:-
1. Boxing & UnBoxing
eg..
Integer iobj = 10;
int i = iobj;
2. Enhanced For Loops
eg..
for(int i=0;i < nums.length;i++)
out.println(nums[i]);
for(int i : nums )
out.println(nums[i]);
3. Enumerations: enum
4. Static Import: Think about using random instead of Math.random();
5. Varargs : Variable length Arguments
6. Formatted IO : Functions like printf()added.
7. Generics: Something related of template in C++. Generic Classes & Methods..
8. MetaData : It is more advanced than javadoc, better support for Implementation Team
9. N/w & security: some new Classes for SSL support
10. Changes in JVM, related to Thread, about different states of Thread.
Well there are many changes these are few to name…
Sending Mails....
A Year Back Our group was in Turmoil of anonymous person sending mails which were unwanted. These mails would contain the names of the group members as the sender, but were sent by the some other person who was solely interested in disrupting the unity of the group.
I had always said it was not a very tough task to do those things. You might have come to sites such as 123greetings.com which send greeting to your friends if you mention your mail-id.
Well all of my given ways would require an SMTP server for Re-direction of mails. The codes cannot change Senders IP Address but can Change the Name. I had many things on my mind by which you can send mails being anonymous. Well some of those can be:-
1. From a Web server (By Some Java API)
2. From a Database Server (By a simple Oracle Procedure)
3. through Outlook.
4. By some Visual Basic features.
5. Sites which offer these facilities.
Of this the easiest one would be 3 & 4 Case.
Here's a code of the Oracle Procedure which will mail to the specified Person. You just need to execute the command from your SqlPlus or any PL/Sql Editor/IDE.
create or replace procedure send_mail (
sender IN VARCHAR2,
recipient IN VARCHAR2,
subject IN VARCHAR2,
message IN VARCHAR2)
IS
v_host_name VARCHAR2(100);
v_host_ip VARCHAR2(100);
v_message varchar2(1000);
crlf VARCHAR2( 2 ):= CHR( 13 ) || CHR( 10 );
mail_conn utl_smtp.connection;
BEGIN
v_host_name := utl_inaddr.get_host_name();
v_host_ip := utl_inaddr.get_host_address(v_host_name);
mail_conn := utl_smtp.open_connection('localhost', 25);
utl_smtp.helo(mail_conn, v_host_ip);
utl_smtp.mail(mail_conn, sender);
utl_smtp.rcpt(mail_conn, recipient);
v_message := 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || crlf ||
'From: ' || sender || crlf ||
'Subject: ' || subject || crlf ||
'To: ' || recipient || '>' || crlf ||
'' || crlf || message;
utl_smtp.data(mail_conn, v_message);
utl_smtp.quit(mail_conn);
dbms_output.put_line('Mail Gaya Bhai Log');
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Error Ho Gaya');
END;
To execute this procedure:-
execute send_mail('sender'sID','recipientID','subject','message' )
Soon I think I will Test the codes for Java & Visual Basic, And the article would be complete.
I had always said it was not a very tough task to do those things. You might have come to sites such as 123greetings.com which send greeting to your friends if you mention your mail-id.
Well all of my given ways would require an SMTP server for Re-direction of mails. The codes cannot change Senders IP Address but can Change the Name. I had many things on my mind by which you can send mails being anonymous. Well some of those can be:-
1. From a Web server (By Some Java API)
2. From a Database Server (By a simple Oracle Procedure)
3. through Outlook.
4. By some Visual Basic features.
5. Sites which offer these facilities.
Of this the easiest one would be 3 & 4 Case.
Here's a code of the Oracle Procedure which will mail to the specified Person. You just need to execute the command from your SqlPlus or any PL/Sql Editor/IDE.
create or replace procedure send_mail (
sender IN VARCHAR2,
recipient IN VARCHAR2,
subject IN VARCHAR2,
message IN VARCHAR2)
IS
v_host_name VARCHAR2(100);
v_host_ip VARCHAR2(100);
v_message varchar2(1000);
crlf VARCHAR2( 2 ):= CHR( 13 ) || CHR( 10 );
mail_conn utl_smtp.connection;
BEGIN
v_host_name := utl_inaddr.get_host_name();
v_host_ip := utl_inaddr.get_host_address(v_host_name);
mail_conn := utl_smtp.open_connection('localhost', 25);
utl_smtp.helo(mail_conn, v_host_ip);
utl_smtp.mail(mail_conn, sender);
utl_smtp.rcpt(mail_conn, recipient);
v_message := 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || crlf ||
'From: ' || sender || crlf ||
'Subject: ' || subject || crlf ||
'To: ' || recipient || '>' || crlf ||
'' || crlf || message;
utl_smtp.data(mail_conn, v_message);
utl_smtp.quit(mail_conn);
dbms_output.put_line('Mail Gaya Bhai Log');
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Error Ho Gaya');
END;
To execute this procedure:-
execute send_mail('sender'sID','recipientID','subject','message' )
Soon I think I will Test the codes for Java & Visual Basic, And the article would be complete.
Tuesday, March 21, 2006
SimpleDateFormat
I have always had problems while converting Dates which are generated by the System into a String. Here's a small code for it.
SimpleDateFormat strDate = new SimpleDateFormat("dd-MMM-yyyy");
String dateStr= strDate.format(new Date() );
System.out.println(dateStr);
SimpleDateFormat strDate = new SimpleDateFormat("dd-MMM-yyyy");
String dateStr= strDate.format(new Date() );
System.out.println(dateStr);
How to get the ClipBoard Contents
I had received a mail from Praveen Some time back. The mail was related to the Clipboard contents which can be copied by certian Websites if you access those sites.
I thought why not experiment on this. As I thought there came two possibilities:
1.Java code which would access the clipboard of the client's computer.
2.The scripting languages which have immense Power, by certain API's one can access the clipboard contents of the client machine. And it would also be easier as the Scripts run on the client's machine itself.
I thought of the 2nd idea, here I give you simple code which will display your last contents of the clipboard. These contents can also be passed to the Server (so called websites).
Just write an Html file and check it yourself.
try.html
I thought why not experiment on this. As I thought there came two possibilities:
1.Java code which would access the clipboard of the client's computer.
2.The scripting languages which have immense Power, by certain API's one can access the clipboard contents of the client machine. And it would also be easier as the Scripts run on the client's machine itself.
I thought of the 2nd idea, here I give you simple code which will display your last contents of the clipboard. These contents can also be passed to the Server (so called websites).
Just write an Html file and check it yourself.
try.html
<script language="JavaScript" >
function display() {
var cbData = window.clipboardData.getData('Text');
alert(cbData);
}
</script>
Click the Button to Know your ClipBoard Contents
<input type="button" value = "Click Me for Information"
onClick="javascript:display()" >
Subscribe to:
Posts (Atom)
Java 10 Features
My blog post in JournalDev for Java 10 Features
-
My blog post in JournalDev for Optional (a Value-Based Class)
-
Here I Come with the Java Code Which can Be used to mail other persons.. Earlier i had written about Oracle Procedure which can send mails. ...
-
My blog post in JournalDev for Programming to Interfaces using static methods in Java Interfaces