Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package epics.server.servlet;
- import java.util.Properties;
- import javax.mail.Message;
- import javax.mail.MessagingException;
- import javax.mail.PasswordAuthentication;
- import javax.mail.Session;
- import javax.mail.Transport;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- //Klasa za email notifikaciju
- public class SendMail {
- public static void sendMessage(String titlep,String messageTextp,String addressp){
- final String title=titlep;
- final String messageText=messageTextp;
- final String address=addressp;
- Thread smt=new Thread(new Runnable() {
- @Override
- public void run() {
- //ovo je server koji salje tj od koga je uvek
- final String username = "epicsE13572@gmail.com";
- final String password = "epicsserver";
- //Ovo moze i u tomee.xml mada mi je odmah ovde preglednije i brze za izmenu
- 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 session = Session.getInstance(props,
- new javax.mail.Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(username, password);
- }
- });
- try {
- // Constructs the message
- Message message = new MimeMessage(session);
- message.setFrom(new InternetAddress(username));//od epicsa
- message.setRecipients(Message.RecipientType.TO,
- InternetAddress.parse(address));//ko se obavestava
- message.setSubject(title);//naslov
- message.setText(messageText);//sadrzaj
- // Sends the message
- Transport.send(message);
- } catch (MessagingException e) {
- e.printStackTrace();
- }
- }
- });
- smt.run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement