Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MailSender {
- private final static String USERNAME = "mail-box adres";
- private final static String PASSWORD = "mail-box password";
- Connection connection;
- public MailSender(Connection connect) {
- connection=connect;
- }
- public void send(List<Message> messageList) throws MessagingException {
- if (messageList==null) throw new NullPointerException("Message error");
- MailRepository dataModificator=new MailRepository(connection);
- Properties props = new Properties();
- props.put("mail.smtp.starttls.enable", "true");
- props.put("mail.smtp.auth", "true");
- props.put("mail.smtp.host", "smtp.gmail.com");
- props.put("mail.smtp.port", "587");
- props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
- Session session = Session.getInstance(props,
- new javax.mail.Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(USERNAME, PASSWORD);
- }
- });
- public class MyClass {
- private static final Properties props = new Properties(){{
- put("mail.smtp.starttls.enable", "true");
- put("mail.smtp.auth", "true");
- put("mail.smtp.host", "smtp.gmail.com");
- put("mail.smtp.port", "587");
- put("mail.smtp.ssl.trust", "smtp.gmail.com");
- }};
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement