Package com.kanner.services

Source Code of com.kanner.services.EmailSvc

package com.kanner.services;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class EmailSvc {

  public String sendEmail() {
   
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);
    Message message = null;
   
    try {
     
      message = new MimeMessage(session);
      message.setFrom(new InternetAddress("me@me.com", "ME"));
      message.addRecipient(Message.RecipientType.TO, new InternetAddress("you@you.com", "YOU"));
     
      message.setSubject("This is a test");
     
      message.setText("This is the body of the text");
     
      Transport.send(message);
     
    } catch (Exception e) {
     
      System.out.println("Exception");
      return "false";
    }
   
    System.out.println(message.toString());
    return "true";
   
  }
}
TOP

Related Classes of com.kanner.services.EmailSvc

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.