Search in sources :

Example 36 with JavaMailSenderImpl

use of org.springframework.mail.javamail.JavaMailSenderImpl in project kylo by Teradata.

the class TestConfiguration method javaMailSender.

@Bean(name = "slaEmailSender")
public JavaMailSender javaMailSender(@Qualifier("slaEmailConfiguration") EmailConfiguration emailConfiguration) {
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    Properties mailProperties = new Properties();
    mailProperties.put("mail.smtp.auth", emailConfiguration.getSmtpAuth());
    mailProperties.put("mail.smtp.starttls.enable", emailConfiguration.getStarttls());
    if (StringUtils.isNotBlank(emailConfiguration.getSmptAuthNtmlDomain())) {
        mailProperties.put("mail.smtp.auth.ntlm.domain", emailConfiguration.getSmptAuthNtmlDomain());
    }
    mailProperties.put("mail.debug", "true");
    mailSender.setJavaMailProperties(mailProperties);
    mailSender.setHost(emailConfiguration.getHost());
    mailSender.setPort(emailConfiguration.getPort());
    mailSender.setProtocol(emailConfiguration.getProtocol());
    mailSender.setUsername(emailConfiguration.getUsername());
    mailSender.setPassword(emailConfiguration.getPassword());
    return mailSender;
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) Properties(java.util.Properties) Bean(org.springframework.context.annotation.Bean)

Example 37 with JavaMailSenderImpl

use of org.springframework.mail.javamail.JavaMailSenderImpl in project oc-explorer by devgateway.

the class EmailServiceConfiguration method javaMailSenderImpl.

@Bean
public JavaMailSenderImpl javaMailSenderImpl() {
    JavaMailSenderImpl jmsi = new JavaMailSenderImpl();
    jmsi.setHost("localhost");
    jmsi.setPort(SMTP_PORT);
    return jmsi;
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) Bean(org.springframework.context.annotation.Bean)

Example 38 with JavaMailSenderImpl

use of org.springframework.mail.javamail.JavaMailSenderImpl in project waltz by khartec.

the class DIConfiguration method mailSender.

@Bean
public JavaMailSender mailSender() {
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setHost(smtpHost);
    mailSender.setPort(smtpPort);
    return mailSender;
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl)

Example 39 with JavaMailSenderImpl

use of org.springframework.mail.javamail.JavaMailSenderImpl in project perun by CESNET.

the class Utils method sendPasswordResetEmail.

/**
	 * Sends email with link to non-authz password reset GUI where user
	 * can reset forgotten password
	 *
	 * @param user user to send notification for
	 * @param email user's email to send notification to
	 * @param namespace namespace to reset password in
	 * @param url base URL of Perun instance
	 * @param id ID of pwd reset request
	 * @throws InternalErrorException
	 */
public static void sendPasswordResetEmail(User user, String email, String namespace, String url, int id) throws InternalErrorException {
    // create mail sender
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setHost("localhost");
    // create message
    SimpleMailMessage message = new SimpleMailMessage();
    message.setTo(email);
    message.setFrom(BeansUtils.getCoreConfig().getMailchangeBackupFrom());
    String instanceName = BeansUtils.getCoreConfig().getInstanceName();
    message.setSubject("[" + instanceName + "] Password reset in namespace: " + namespace);
    // get validation link params
    String i = cipherInput(String.valueOf(user.getId()), false);
    String m = cipherInput(String.valueOf(id), false);
    try {
        URL urlObject = new URL(url);
        StringBuilder link = new StringBuilder();
        link.append(urlObject.getProtocol());
        link.append("://");
        link.append(urlObject.getHost());
        // reset link uses non-authz
        link.append("/non/pwd-reset/");
        link.append("?i=");
        link.append(URLEncoder.encode(i, "UTF-8"));
        link.append("&m=");
        link.append(URLEncoder.encode(m, "UTF-8"));
        // Build message
        String text = "Dear " + user.getDisplayName() + ",\n\nWe've received request to reset your password in namespace \"" + namespace + "\"." + "\n\nPlease visit the link below, where you can set new password:\n\n" + link + "\n\n" + "Message is automatically generated." + "\n----------------------------------------------------------------" + "\nPerun - Identity & Access Management System";
        message.setText(text);
        mailSender.send(message);
    } catch (UnsupportedEncodingException ex) {
        throw new InternalErrorException("Unable to encode URL for password reset.", ex);
    } catch (MalformedURLException ex) {
        throw new InternalErrorException("Not valid URL of running Perun instance.", ex);
    }
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) MalformedURLException(java.net.MalformedURLException) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) URL(java.net.URL)

Example 40 with JavaMailSenderImpl

use of org.springframework.mail.javamail.JavaMailSenderImpl in project gravitee-management-rest-api by gravitee-io.

the class EmailConfiguration method mailSender.

@Bean
public JavaMailSenderImpl mailSender() {
    final JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
    javaMailSender.setHost(host);
    if (StringUtils.isNumeric(port)) {
        javaMailSender.setPort(Integer.valueOf(this.port));
    }
    javaMailSender.setUsername(username);
    javaMailSender.setPassword(password);
    javaMailSender.setProtocol(protocol);
    javaMailSender.setJavaMailProperties(loadProperties());
    return javaMailSender;
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) Bean(org.springframework.context.annotation.Bean)

Aggregations

JavaMailSenderImpl (org.springframework.mail.javamail.JavaMailSenderImpl)56 Properties (java.util.Properties)25 Bean (org.springframework.context.annotation.Bean)14 MimeMessage (javax.mail.internet.MimeMessage)11 MessagingException (javax.mail.MessagingException)10 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)10 Test (org.junit.Test)9 JavaMailSender (org.springframework.mail.javamail.JavaMailSender)6 Date (java.util.Date)4 IOException (java.io.IOException)3 ByteArrayResource (org.springframework.core.io.ByteArrayResource)3 MailException (org.springframework.mail.MailException)3 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)3 GreenMail (com.icegreen.greenmail.util.GreenMail)2 BufferedReader (java.io.BufferedReader)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2