-drag and drop 4 Lebel named: phone no, gmail, password, message
-drag and drop 2 TextField for phone no and gmail
-drag and dropPassword Field for gmail password
-drag and drop TextArea for message
drag and drop one Button
Write the following code by double clicking the button.
code:
Import following library
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.internet.MimeMessage;
import javax.swing.JOptionPane;
try{
String host = "smtp.gmail.com";
String user = txtGmail.getText();
String pss = txtPass.getText();
String to = txtPhone.getText();
String from = user;
String subject = "Message";
String message = txtMessage.getText();
boolean sessionDebug = false;
Properties pros = System.getProperties();
pros.put("mail.smtp.starttls.enable", "tue");
pros.put("mail.smtp.host", "host");
pros.put("mail.smtp.auth","true");
pros.put("mail.smtp.port","587");
pros.put("mail.smtp.starttls.required","true");
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Session mailSession = Session.getDefaultInstance(pros,null);
mailSession.setDebug(sessionDebug);
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress [] address ={new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(message);
Transport transport = mailSession.getTransport("smtp");
transport.connect(host, user, pss);
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
JOptionPane.showMessageDialog(null,"message send successfully");
}
catch(Exception ex){
JOptionPane.showMessageDialog(null, ex);
}
for more information on how to add mail.jar file and activation.jar file you must watch the following video:
-drag and drop 2 TextField for phone no and gmail
-drag and dropPassword Field for gmail password
-drag and drop TextArea for message
drag and drop one Button
Write the following code by double clicking the button.
code:
Import following library
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.internet.MimeMessage;
import javax.swing.JOptionPane;
try{
String host = "smtp.gmail.com";
String user = txtGmail.getText();
String pss = txtPass.getText();
String to = txtPhone.getText();
String from = user;
String subject = "Message";
String message = txtMessage.getText();
boolean sessionDebug = false;
Properties pros = System.getProperties();
pros.put("mail.smtp.starttls.enable", "tue");
pros.put("mail.smtp.host", "host");
pros.put("mail.smtp.auth","true");
pros.put("mail.smtp.port","587");
pros.put("mail.smtp.starttls.required","true");
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Session mailSession = Session.getDefaultInstance(pros,null);
mailSession.setDebug(sessionDebug);
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress [] address ={new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(message);
Transport transport = mailSession.getTransport("smtp");
transport.connect(host, user, pss);
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
JOptionPane.showMessageDialog(null,"message send successfully");
}
catch(Exception ex){
JOptionPane.showMessageDialog(null, ex);
}
for more information on how to add mail.jar file and activation.jar file you must watch the following video:
can i make this program in jsp(java server page)
ReplyDelete