Search in sources :

Example 1 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project spring-boot-admin by codecentric.

the class MailNotifier method doNotify.

@Override
protected void doNotify(ClientApplicationEvent event) {
    EvaluationContext context = new StandardEvaluationContext(event);
    SimpleMailMessage message = new SimpleMailMessage();
    message.setTo(to);
    message.setFrom(from);
    message.setSubject(subject.getValue(context, String.class));
    message.setText(text.getValue(context, String.class));
    message.setCc(cc);
    sender.send(message);
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) EvaluationContext(org.springframework.expression.EvaluationContext)

Example 2 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project perun by CESNET.

the class Utils method sendPasswordResetConfirmationEmail.

/**
	 * Sends email to user confirming his password was changed.
	 *
	 * @param user user to send notification for
	 * @param email user's email to send notification to
	 * @param namespace namespace the password was re-set
	 * @throws InternalErrorException
	 */
public static void sendPasswordResetConfirmationEmail(User user, String email, String namespace) 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(namespace, false);
    // Build message
    String text = "Dear " + user.getDisplayName() + ",\n\nyour password in namespace \"" + namespace + "\" was successfully reset." + "\n\nThis message is automatically sent to all your email addresses registered in " + instanceName + " in order to prevent malicious password reset without your knowledge.\n\n" + "If you didn't request / perform password reset, please notify your administrators and support at " + BeansUtils.getCoreConfig().getMailchangeBackupFrom() + " to resolve this security issue.\n\n" + "Message is automatically generated." + "\n----------------------------------------------------------------" + "\nPerun - Identity & Access Management System";
    message.setText(text);
    mailSender.send(message);
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) SimpleMailMessage(org.springframework.mail.SimpleMailMessage)

Example 3 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project perun by CESNET.

the class Utils method sendValidationEmail.

/**
	 * Send validation email related to requested change of users preferred email.
	 *
	 * @param user user to change preferred email for
	 * @param url base URL of running perun instance passed from RPC
	 * @param email new email address to send notification to
	 * @param changeId ID of change request in DB
	 * @throws InternalErrorException
	 */
public static void sendValidationEmail(User user, String url, String email, int changeId) 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 + "] New email address verification");
    // get validation link params
    String i = Integer.toString(changeId, Character.MAX_RADIX);
    String m = Utils.getMessageAuthenticationCode(i);
    try {
        // !! There is a hard-requirement for Perun instance
        // to host GUI on same server as RPC like: "serverUrl/gui/"
        URL urlObject = new URL(url);
        // use default if unknown rpc path
        String path = "/gui/";
        if (urlObject.getPath().contains("/krb/")) {
            path = "/krb/gui/";
        } else if (urlObject.getPath().contains("/fed/")) {
            path = "/fed/gui/";
        } else if (urlObject.getPath().contains("/cert/")) {
            path = "/cert/gui/";
        }
        StringBuilder link = new StringBuilder();
        link.append(urlObject.getProtocol());
        link.append("://");
        link.append(urlObject.getHost());
        link.append(path);
        link.append("?i=");
        link.append(URLEncoder.encode(i, "UTF-8"));
        link.append("&m=");
        link.append(URLEncoder.encode(m, "UTF-8"));
        link.append("&u=" + user.getId());
        // Build message
        String text = "Dear " + user.getDisplayName() + ",\n\nWe've received request to change your preferred email address to: " + email + "." + "\n\nTo confirm this change please use link below:\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 validation URL for mail change.", 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 4 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project Internet-Software-Architectures by zivko11.

the class Mailing method sendBidAcceptedNotification.

public void sendBidAcceptedNotification(String mail, String propsName) {
    String subject = "Your bid is accepted!";
    String link = "localhost:8080/cinema-theatre/fanzone.html?propsid=";
    String message = "Congratulations! Your bid for " + propsName + " is accepted. You can see props status here: ";
    SimpleMailMessage email = new SimpleMailMessage();
    email.setTo(mail);
    email.setSubject(subject);
    email.setText(message + link);
    mailSender.send(email);
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage)

Example 5 with SimpleMailMessage

use of org.springframework.mail.SimpleMailMessage in project Internet-Software-Architectures by zivko11.

the class Mailing method sendBidRejectedNotification.

public void sendBidRejectedNotification(String mail, String propsName) {
    String subject = "Your bid is rejected!";
    String link = "localhost:8080/cinema-theatre/fanzone.html?propsid=";
    String message = "Unfortunately, your bid for " + propsName + " is rejected. You can see props status here: ";
    SimpleMailMessage email = new SimpleMailMessage();
    email.setTo(mail);
    email.setSubject(subject);
    email.setText(message + link);
    mailSender.send(email);
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage)

Aggregations

SimpleMailMessage (org.springframework.mail.SimpleMailMessage)106 MailException (org.springframework.mail.MailException)17 Test (org.junit.Test)13 Test (org.testng.annotations.Test)7 Test (org.junit.jupiter.api.Test)6 User (org.molgenis.data.security.auth.User)5 JavaMailSender (org.springframework.mail.javamail.JavaMailSender)5 IOException (java.io.IOException)4 MessagingException (javax.mail.MessagingException)4 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 MailSendException (org.springframework.mail.MailSendException)4 InternetAddress (jakarta.mail.internet.InternetAddress)3 MimeMessage (jakarta.mail.internet.MimeMessage)3 Date (java.util.Date)3 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)3 MolgenisUserException (org.molgenis.security.user.MolgenisUserException)3 JavaMailSenderImpl (org.springframework.mail.javamail.JavaMailSenderImpl)3 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 User (fr.codechill.spring.model.User)2