use of org.springframework.mail.SimpleMailMessage in project webofneeds by researchstudio-sat.
the class WonMailSenderTest method sendTextMessage.
@Test
public void sendTextMessage() throws MessagingException {
SimpleMailMessage message = new SimpleMailMessage();
// replace sender specified in mail-sender.xml with the test sender
message.setFrom("test@sender.com");
wonEmailSender.sendTextMessage("test@receiver.com", "test subject", "test message");
Message[] messages = testSmtp.getReceivedMessages();
Assert.assertTrue(messages.length == 1);
Assert.assertEquals("test subject", messages[0].getSubject());
String body = GreenMailUtil.getBody(messages[0]).replaceAll("=\r?\n", "");
Assert.assertEquals("test message", body);
}
use of org.springframework.mail.SimpleMailMessage in project ocvn by devgateway.
the class SendEmailService method sendEmailResetPassword.
/**
* Send a reset password email. This is UNSAFE because passwords are sent in clear text.
* Nevertheless some customers will ask for these emails to be sent, so ...
* @param person
* @param newPassword
*/
public void sendEmailResetPassword(final Person person, final String newPassword) {
SimpleMailMessage msg = new SimpleMailMessage();
msg.setTo(person.getEmail());
msg.setFrom("support@developmentgateway.org");
msg.setSubject("Recover your password");
msg.setText("Dear " + person.getFirstName() + " " + person.getLastName() + ",\n\n" + "These are your new login credentials for E-Procurement Toolkit.\n\n" + "Username: " + person.getUsername() + "\n" + "Password: " + newPassword + "\n\n" + "At login, you will be prompted to change your password to one of your choice.\n\n" + "Thank you,\n" + "DG Team");
try {
javaMailSenderImpl.send(msg);
} catch (MailException e) {
e.printStackTrace();
}
}
use of org.springframework.mail.SimpleMailMessage in project paascloud-master by paascloud.
the class OptSendMailServiceImpl method sendSimpleMail.
@Override
public int sendSimpleMail(String subject, String text, Set<String> to) {
log.info("sendSimpleMail - 发送简单邮件. subject={}, text={}, to={}", subject, text, to);
int result = 1;
try {
SimpleMailMessage message = MailEntity.createSimpleMailMessage(subject, text, to);
message.setFrom(from);
taskExecutor.execute(() -> mailSender.send(message));
} catch (Exception e) {
log.info("sendSimpleMail [FAIL] ex={}", e.getMessage(), e);
result = 0;
}
return result;
}
use of org.springframework.mail.SimpleMailMessage in project webapp by elimu-ai.
the class Mailer method sendPlainText.
public static void sendPlainText(String to, String cc, String from, String subject, String text) {
logger.info("sendPlainText");
if (to.contains(",")) {
to = to.replace(",", "");
}
if (to.contains(":")) {
to = to.replace(":", "");
}
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setTo(to);
if (StringUtils.isNotBlank(cc)) {
simpleMailMessage.setCc(cc);
}
simpleMailMessage.setBcc(ADMIN_EMAIL);
simpleMailMessage.setFrom(from);
simpleMailMessage.setSubject(subject);
simpleMailMessage.setText(text);
JavaMailSenderImpl javaMailSenderImpl = new JavaMailSenderImpl();
String smtpHost = ConfigHelper.getProperty("smtp.host");
javaMailSenderImpl.setHost(smtpHost);
logger.info("Sending e-mail to " + simpleMailMessage.getTo()[0] + " with subject \"" + simpleMailMessage.getSubject() + "\"...");
logger.info("Text: " + simpleMailMessage.getText());
if (EnvironmentContextLoaderListener.env != Environment.DEV) {
javaMailSenderImpl.send(simpleMailMessage);
}
}
use of org.springframework.mail.SimpleMailMessage in project microservices by pwillhan.
the class MailService method sendGenericMail.
public void sendGenericMail(String email, String subject, String body) {
SimpleMailMessage msg = new SimpleMailMessage();
msg.setTo(email);
msg.setFrom(env.getProperty("com.cassandrawebtrader.mail.from"));
msg.setSubject(subject);
msg.setText(body);
try {
mailSender.send(msg);
logger.info(msg.toString());
} catch (MailException e) {
logger.error(e.getMessage());
}
}
Aggregations