Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Properties;
- import javax.mail.*;
- import javax.mail.Message;
- import javax.mail.MessagingException;
- import javax.mail.Session;
- import javax.mail.Transport;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- public class birthdaywishscheduler {
- public static void main(String args[]){
- final String username = "gfcgcc987@gmail.com";
- final String password = "jhgvjhbjj";
- final String to = mailid;
- final String subject = "Happy Birthday from our company";
- final String messg = "Have a wonderful birthday! Dear QWERTY It’s our pleasure to wish you the best day of the year";
- final String from = "gfcgcc987@gmail.com";
- final String pass = "jhgvjhbjj";
- Properties props = new Properties();
- props.put("mail.smtp.auth", true);
- props.put("mail.smtp.starttls.enable", true);
- props.put("mail.smtp.host", "smtp.gmail.com");
- props.put("mail.smtp.port", "587");
- Session session1 = Session.getInstance(props,
- new javax.mail.Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(username, password);
- }
- });
- try {
- Message message = new MimeMessage(session1);
- message.setFrom(new InternetAddress(from));
- message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
- message.setSubject(subject);
- message.setText(messg);
- // Send message
- Transport.send(message);
- System.out.print("Your mail sent successfully....");
- } catch (MessagingException mex) {
- mex.printStackTrace();
- //out.println(mex);
- System.out.print("Error: unable to send mail....");
- }
- }
- }
Add Comment
Please, Sign In to add comment