java.lang.Object
javax.mail.Address
javax.mail.internet.InternetAddress
- All Implemented Interfaces:
- Cloneable, Serializable
- See Also:
- Top Examples, Source Code
protected String address
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[227]Send confidential mail
By Anonymous on 2005/04/26 15:26:23 Rate
import java.util.Date;
import java.util.Properties;
import javax.naming.*;
import javax.mail.*;
import javax.mail.internet.*;
....
// Local reference to the javax.mail.Session
javax.mail.Session mailSession = null;
try {
Context ctx = new InitialContext ( ) ;
// Get the properties from this bean from the environment. The
// properties were specified in the env-entry tags in the deployment
// descriptor for this bean
Context myEnv = ( Context ) ctx.lookup ( "java:comp/env" ) ;
String smtpHost = ( String ) myEnv.lookup ( "smtpHost" ) ;
Properties props = new Properties ( ) ;
props.put ( "mail.smtp.host", smtpHost ) ;
// Get a mail session. You would normally get this from
// JNDI, but some servers have a problem with this.
// Each Message Driven bean instance is responsible for
//getting its own unshared javax.mail.Session.
mailSession = javax.mail.Session.getDefaultInstance ( props, null ) ;
javax.mail.Message msg = new MimeMessage ( mailSession ) ;
// Set the mail properties
msg.setFrom ( new javax.mail.internet.InternetAddress ( "FromSomeone@KickJava.com" ) ;
InternetAddress [ ] addresses = {
new InternetAddress ( "ToSomeone@Kickjava.com" )
} ;
msg.setRecipients ( javax.mail.Message.RecipientType.TO, addresses ) ;
msg.setSubject ( "Subject" ) ;
msg.setSentDate ( new Date ( ) ) ;
// Create the body text
Multipart parts = new MimeMultipart ( ) ;
MimeBodyPart mainBody = new MimeBodyPart ( ) ;
mainBody.setText ( "Hello Body" ) ;
parts.addBodyPart ( mainBody ) ;
MimeBodyPart attachmentBody = new MimeBodyPart ( ) ;
attachmentBody.setText ( "This is text in the attachment" ) ;
attachmentBody.addBodyPart ( p2 ) ;
// Set some header fields
msg.setHeader ( "X-Priority", "High" ) ;
msg.setHeader ( "Sensitivity", "Company-Confidential" ) ;
msg.setContent ( parts ) ;
System.out.println ( "Sending mail to support@KickJava.com" ) ;
Transport.send ( msg ) ;
}
catch ( Exception ex ) {
ex.printStackTrace ( ) ;
}
finally {
mailSession = null;
}
[2014]Browse the file and transfer using UDP client and server method in java using swings.
By karthisoft { dot } 123 { at } gmail { dot } com on 2010/11/13 02:23:11 Rate
Server side program:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class UDPSendServerRequest {
JFrame frame;
JPanel panel;
JButton button1,button2;
JTextArea area;
JScrollPane pane;
Thread thread;
DatagramSocket socket;
public static void main ( String [ ] args ) {
UDPSendServerRequest u = new UDPSendServerRequest ( ) ;
}
public UDPSendServerRequest ( ) {
frame = new JFrame ( "Text Server" ) ;
frame.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ) ;
frame.setUndecorated ( true ) ;
frame.getRootPane ( ) .setWindowDecorationStyle ( JRootPane.PLAIN_DIALOG ) ;
panel = new JPanel ( ) ;
panel.setLayout ( null ) ;
area = new JTextArea ( ) ;
area.setEditable ( false ) ;
button1 = new JButton ( "Start" ) ;
button1.setBounds ( 210, 10, 75, 40 ) ;
button1.addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent ae ) {
new StartThread ( ) ;
}
} ) ;
panel.add ( button1 ) ;
button2 = new JButton ( "Stop" ) ;
button2.setBounds ( 300, 10, 75, 40 ) ;
button2.addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent ae ) {
thread.interrupted ( ) ;
socket.close ( ) ;
area.append ( "Server is stopped\n" ) ;
button1.setEnabled ( true ) ;
button2.setEnabled ( false ) ;
}
} ) ;
button2.setEnabled ( false ) ;
panel.add ( button2 ) ;
pane = new JScrollPane ( area ) ;
pane.setBounds ( 10, 60, 365, 250 ) ;
panel.add ( pane ) ;
frame.add ( panel ) ;
frame.setSize ( 400, 400 ) ;
frame.setVisible ( true ) ;
}
public class StartThread implements Runnable {
StartThread ( ) {
thread = new Thread ( this ) ;
thread.start ( ) ;
button1.setEnabled ( false ) ;
button2.setEnabled ( true ) ;
}
public void run ( ) {
try {
byte [ ] buffer = new byte [ 1024 ] ;
int port = 8080;
String message;
try {
socket = new DatagramSocket ( port ) ;
while ( true ) {
try {
area.append ( "Server is started\n" ) ;
//Receive request from client
DatagramPacket packet = new DatagramPacket ( buffer, buffer.length ) ;
socket.receive ( packet ) ;
InetAddress client = packet.getAddress ( ) ;
int client_port = packet.getPort ( ) ;
area.append ( " Received "+new String ( buffer ) +" from "+client ) ;
// send information to the client
message = "your request\n ";
buffer = message.getBytes ( ) ;
packet = new DatagramPacket ( buffer, buffer.length, client, client_port ) ;
socket.send ( packet ) ;
}
catch ( UnknownHostException ue ) { }
}
}
catch ( java.net.BindException b ) { }
}
catch ( IOException e ) {
System.err.println ( e ) ;
}
}
}
}
client side program:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class RecUDPClient {
JFrame frame;
JFileChooser chooser;
JPanel panel;
JTextField field1, field2, field3;
JTextArea area;
JScrollPane pane;
JLabel label;
JButton button1, button2;
public static void main ( String [ ] args ) {
RecUDPClient u = new RecUDPClient ( ) ;
}
public RecUDPClient ( ) {
frame = new JFrame ( "Text Client" ) ;
frame.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ) ;
frame.setUndecorated ( true ) ;
frame.getRootPane ( ) .setWindowDecorationStyle ( JRootPane.PLAIN_DIALOG ) ;
panel = new JPanel ( ) ;
panel.setLayout ( null ) ;
label = new JLabel ( "Desination IP:" ) ;
label.setBounds ( 10, 20, 100, 30 ) ;
panel.add ( label ) ;
field1 = new JTextField ( 20 ) ;
field1.setBounds ( 125, 25, 150, 20 ) ;
panel.add ( field1 ) ;
label = new JLabel ( "Destination Port:" ) ;
label.setBounds ( 10, 50, 100, 30 ) ;
panel.add ( label ) ;
field2 = new JTextField ( 10 ) ;
field2.setBounds ( 125, 55, 100, 20 ) ;
panel.add ( field2 ) ;
area = new JTextArea ( ) ;
pane = new JScrollPane ( area ) ;
pane.setBounds ( 10, 120, 300, 200 ) ;
panel.add ( label ) ;
field3=new JTextField ( 5 ) ;
field3.setBounds ( 20,95,175,20 ) ;
panel.add ( field3 ) ;
panel.add ( pane ) ;
button2=new JButton ( "Browse" ) ;
button2.setBounds ( 195,95,95,20 ) ;
button2.addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent avt ) {
String filename=File.separator+"tmp";
JFileChooser fc=new JFileChooser ( new File ( filename ) ) ;
fc.showOpenDialog ( frame ) ;
File selFile=fc.getSelectedFile ( ) ;
}
} ) ;
button1 = new JButton ( "Send" ) ;
button1.setBounds ( 235, 330, 75, 30 ) ;
button1.addActionListener ( new ActionListener ( ) {
public void actionPerformed ( ActionEvent ae ) {
new SendRequest ( ) ;
}
} ) ;
panel.add ( button1 ) ;
panel.add ( button2 ) ;
frame.add ( panel ) ;
frame.setSize ( 400, 400 ) ;
frame.setVisible ( true ) ;
}
public class SendRequest {
SendRequest ( ) {
try {
DatagramSocket socket;
DatagramPacket packet;
InetAddress address;
socket = new DatagramSocket ( ) ;
String dip = field1.getText ( ) ;
address = InetAddress.getByName ( dip ) ;
String port = field2.getText ( ) ;
int pnum = Integer.parseInt ( port ) ;
//For send the message by the client
String mess = area.getText ( ) ;
byte message [ ] = mess.getBytes ( ) ;
packet = new DatagramPacket ( message, message.length, address, pnum ) ;
socket.send ( packet ) ;
area.setText ( "" ) ;
//For Received message
packet = new DatagramPacket ( message, message.length ) ;
socket.receive ( packet ) ;
String recmessage = new String ( packet.getData ( ) ) ;
area.append ( "Received from server: " + recmessage ) ;
socket.close ( ) ;
}
catch ( IOException io ) { }
}
}
}
You will sure get output. please try it.
public Object clone()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected String encodedPersonal
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public boolean equals(Object a)
- See Also:
- Address
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public String getAddress()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public InternetAddress[] getGroup(boolean strict)
throws AddressException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[2019]Send mail to Group of Recipients
By gulabmeetyou { at } gmail { dot } com on 2012/02/19 00:26:17 Rate
Set the group of recipients in TO address.
public static InternetAddress getLocalAddress(Session session)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public String getPersonal()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public String getType()
- See Also:
InternetAddress
, Address
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int hashCode()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public InternetAddress()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public InternetAddress(String address)
throws AddressException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public InternetAddress(String address,
boolean strict)
throws AddressException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public InternetAddress(String address,
String personal)
throws UnsupportedEncodingException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public InternetAddress(String address,
String personal,
String charset)
throws UnsupportedEncodingException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public boolean isGroup()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static InternetAddress[] parse(String addresslist)
throws AddressException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static InternetAddress[] parse(String addresslist,
boolean strict)
throws AddressException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[861]Send SMTP mail
By Ankur on 2004/08/19 04:40:11 Rate
import java.io.*;
import java.util.Date;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import oracle.jdbc.driver.OracleTypes;
import java.sql.*;
import javax.sql.*;
public class Mail
{
String mailhost;
String mailport;
String from;
String to;
String body;
String body1;
String to_usrid;
String from_usrid;
private til.util.dbpool.ConnectionPool connectDB = null;
public Mail ( String s String s1 )
{
to_usrid=s;
from_usrid=s1;
mailhost="localhost";
mailport="**";
subject="Urgent,your club may be deleted soon";
}
public void work ( )
{
try
{
String s = "";
s = to_usrid;
String s1 = "";
s1 = from_usrid;
BufferedReader bufferreader = new BufferReader ( new InputStreamReader ( System.in ) ) ;
java.util.Properties properties = System.getProperties ( ) ;
properties.put ( "mail.smtp.host", mailhost ) ;
properties.put ( "mail.smtp.port", mailport ) ;
Session session = Session.getInstance ( properties, null ) ;
MimeMessage mimemessage = new MimeMessage ( session ) ;
mimemessage.setFrom ( new InternetAddress ( from ) ;
mimemessage.setRicipients ( new javax.mail.Message.RecipientType.To, InternetAddress.parse ( s,false ) ) ;
mimemessage.setSubject ( subject ) ;
format ( message ) ;
mimemessage.setSentDate ( new Date ( ) ) ;
Transport.send ( mimemessage ) ;
System.out.println ( "**************Mail has been send successfully**************" ) ;
}
catch ( Exception ex )
{
System.out.println ( "Exception Caught ex" ) ;
ex.printStackTrace ( ) ;
}
public static InternetAddress[] parseHeader(String addresslist,
boolean strict)
throws AddressException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected String personal
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void setAddress(String address)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void setPersonal(String name)
throws UnsupportedEncodingException
- See Also:
setPersonal(String name, String charset)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void setPersonal(String name,
String charset)
throws UnsupportedEncodingException
- See Also:
setPersonal(String)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public String toString()
- See Also:
- Address
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static String toString(Address[] addresses)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static String toString(Address[] addresses,
int used)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public String toUnicodeString()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void validate()
throws AddressException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples