Package javax.mail

Examples of javax.mail.Authenticator


    @Override
    public void send(EmailTransmitterConfiguration configuration, Escalation escalation) {
        Properties props = createProperties(configuration);

        Authenticator authenticator = createAuthenticator(configuration);
        Session session = Session.getInstance(props, authenticator);

        MimeMessage message = new MimeMessage(session);
        try {
            message.setRecipients(Message.RecipientType.TO, getToAddresses(configuration));
View Full Code Here


        return props;
    }

    private Authenticator createAuthenticator(final EmailTransmitterConfiguration config) {
        Authenticator authenticator = null;
        if (config.isAuthorizationRequired()) {

            authenticator = new Authenticator() {
                private PasswordAuthentication pa = new PasswordAuthentication(config.getUserName(), config.getPassword());

                @Override
                public PasswordAuthentication getPasswordAuthentication() {
                    return pa;
View Full Code Here

            return Session.getInstance(props,getAuthenticator(smtpAuthUserName,Secret.toString(smtpAuthPassword)));
        }

        private static Authenticator getAuthenticator(final String smtpAuthUserName, final String smtpAuthPassword) {
            if(smtpAuthUserName==null)    return null;
            return new Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(smtpAuthUserName,smtpAuthPassword);
                }
            };
View Full Code Here

        if (smtpUser == null || smtpUser.equals("") || smtpUser.equals("null")) {
            this.session = Session.getInstance(properties);
        } else {
            properties.put("mail.smtp.auth", "true");
            this.session = Session.getInstance(properties, new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(smtpUser, smtpPswd);
                }
            });
        }
View Full Code Here

            // Aside, the JDK is clearly unaware of the Scottish
            // 'session', which involves excessive quantities of
            // alcohol :-)
            Session sesh;
            Authenticator auth;
            if (SSL) {
                try {
                    Provider p
                        = (Provider) Class.forName("com.sun.net.ssl.internal.ssl.Provider").newInstance();
                    Security.addProvider(p);
View Full Code Here

                        }

                        props.put(attr.getType(), (String) attr.getContent());
                    }

                    Authenticator auth = null;
                    if (password != null) {
                        String user = props.getProperty("mail.smtp.user");
                        if(user == null) {
                            user = props.getProperty("mail.user");
                        }
                       
                        if(user != null) {
                            final PasswordAuthentication pa = new PasswordAuthentication(user, password);
                            auth = new Authenticator() {
                                    protected PasswordAuthentication getPasswordAuthentication() {
                                        return pa;
                                    }
                                };
                        }
View Full Code Here

    public synchronized Session getInstance() {
        if (instance != null) {
            return instance;
        }

        Authenticator authenticator = null;
        if (mailSmtpAuth) {
            final PasswordAuthentication pauth = new PasswordAuthentication(mailUser, mailPassword);
            authenticator = new Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return pauth;
                }
            };
View Full Code Here

  protected Session createSession() {
    Properties props = new Properties();
    props.put("mail.smtps.host", getSMTPHost());
    props.put("mail.smtps.auth", "true");
   
    Authenticator auth = null;
    if ((getSMTPPassword() != null) && (getSMTPUsername() != null)) {
      auth = new Authenticator() {
       
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication(getSMTPUsername(), getSMTPPassword());
        }
View Full Code Here

            mailProps.put("mail.smtp.socketFactory.port", "465");
            mailProps.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
            mailProps.put("mail.smtp.socketFactory.fallback", "false");

            //EH NECESSARIO AUTENTICAR
            Session mailSession = Session.getInstance(mailProps, new Authenticator() {                 
                public PasswordAuthentication getPasswordAuthentication(){             
                    return new PasswordAuthentication(emailRemetente, senhaRemetente);
                }
            });
            mailSession.setDebug(false);
View Full Code Here

  }

  private Session getSession(final Properties properties)
      throws NoSuchProviderException {
    final Session session = Session.getDefaultInstance(properties,
        new Authenticator() {
          @Override
          protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(
                properties
                    .getProperty(Constants.EMAIL_USERNAME_PROPERTY),
View Full Code Here

TOP

Related Classes of javax.mail.Authenticator

Copyright © 2018 www.massapicom. 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.