Create Your Own Mail Sender In JAVA
import com.sun.mail.smtp.SMTPTransport;
import java.security.Security;
import java.util.Date;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.*;
import javax.swing.JOptionPane;
public class NewJFrame extends javax.swing.JFrame {
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
try{
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com"); // for gmail use smtp.gmail.com smtp.mail.yahoo.com
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
Session mailSession = Session.getInstance(props, new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("Your Email","Password");
}
});
mailSession.setDebug(true); // Enable the debug mode
Message msg = new MimeMessage( mailSession );
//--[ Set the FROM, TO, DATE and SUBJECT fields
msg.setFrom( new InternetAddress( "Your email" ) );
msg.setRecipients( Message.RecipientType.TO,InternetAddress.parse("Reciever Email") );
msg.setSentDate( new Date());
msg.setSubject("Subject");
//--[ Create the body of the mail
msg.setText( "Message" );
//--[ Ask the Transport class to send our mail message
Transport.send( msg );
JOptionPane.showMessageDialog(null, "Sent");
}catch(Exception Pankaj){
JOptionPane.showMessageDialog(null,Pankaj);// System.out.println(E);
}}
import java.security.Security;
import java.util.Date;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.*;
import javax.swing.JOptionPane;
public class NewJFrame extends javax.swing.JFrame {
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
try{
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com"); // for gmail use smtp.gmail.com smtp.mail.yahoo.com
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
Session mailSession = Session.getInstance(props, new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("Your Email","Password");
}
});
mailSession.setDebug(true); // Enable the debug mode
Message msg = new MimeMessage( mailSession );
//--[ Set the FROM, TO, DATE and SUBJECT fields
msg.setFrom( new InternetAddress( "Your email" ) );
msg.setRecipients( Message.RecipientType.TO,InternetAddress.parse("Reciever Email") );
msg.setSentDate( new Date());
msg.setSubject("Subject");
//--[ Create the body of the mail
msg.setText( "Message" );
//--[ Ask the Transport class to send our mail message
Transport.send( msg );
JOptionPane.showMessageDialog(null, "Sent");
}catch(Exception Pankaj){
JOptionPane.showMessageDialog(null,Pankaj);// System.out.println(E);
}}
Labels
JAVA Project
Post A Comment
No comments :
Be The first to comment! among your friends