Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- * https://www.google.com/settings/security/lesssecureapps
- */
- package SendEmail;
- /**
- *
- * @author Naveen
- */
- import java.util.*;
- import javax.mail.*;
- import javax.mail.internet.*;
- import javax.mail.internet.MimeMessage;
- public class EmailSend {
- public static void main(String args[]){
- try{
- String host ="smtp.gmail.com" ;
- String user = "your email address";
- String pass = "your password";
- String to = "receiever email ";
- String from = "sender email";
- String subject = "This is confirmation number for your expertprogramming account. Please insert this number to activate your account.";
- String messageText = "Your Is Test Email :";
- boolean sessionDebug = false;
- Properties props = System.getProperties();
- props.put("mail.smtp.starttls.enable", "true");
- props.put("mail.smtp.host", host);
- props.put("mail.smtp.port", "587");
- props.put("mail.smtp.auth", "true");
- props.put("mail.smtp.starttls.required", "true");
- java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
- Session mailSession = Session.getDefaultInstance(props, 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(messageText);
- Transport transport=mailSession.getTransport("smtp");
- transport.connect(host, user, pass);
- transport.sendMessage(msg, msg.getAllRecipients());
- transport.close();
- System.out.println("message send successfully");
- }catch(Exception ex)
- {
- System.out.println(ex);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement