+package businessLogic;
+
+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 com.sun.mail.smtp.SMTPTransport;
+
+public class MailManager {
+
+ private String user = "ruralhousesrh";
+ private String password = "RHRHRHRHRH";
+ private static MailManager mm = null;
+
+ public static MailManager getInstance() {
+ if (mm == null)
+ return new MailManager();
+ else
+ return mm;
+ }
+
+
+ public void Send( String recipientEmail, String title, String message) throws AddressException, MessagingException {
+
+ Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
+ final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
+
+
+ Properties props = System.getProperties();
+ props.setProperty("mail.smtps.host", "smtp.gmail.com");
+ props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
+ props.setProperty("mail.smtp.socketFactory.fallback", "false");
+ props.setProperty("mail.smtp.port", "465");
+ props.setProperty("mail.smtp.socketFactory.port", "465");
+ props.setProperty("mail.smtps.auth", "true");
+
+ props.put("mail.smtps.quitwait", "false");
+
+ Session session = Session.getInstance(props, null);
+
+ // -- Create a new message --
+ final MimeMessage msg = new MimeMessage(session);
+
+ // -- Set the FROM and TO fields --
+ msg.setFrom(new InternetAddress(user + "@gmail.com"));
+ msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipientEmail, false));
+
+
+ msg.setSubject(title);
+ msg.setText(message, "utf-8");
+ msg.setSentDate(new Date());
+
+ SMTPTransport t = (SMTPTransport)session.getTransport("smtps");
+
+ t.connect("smtp.gmail.com", user, password);
+ t.sendMessage(msg, msg.getAllRecipients());
+ t.close();
+ }
+}
\ No newline at end of file