use of org.springframework.mail.MailException in project bamboobsc by billchen198318.
the class MailClientUtils method send.
public static void send(String from, String to, String[] cc, String[] bcc, String[] fileNames, File[] files, String subject, String text) throws MailException, Exception {
if (mailSender == null) {
throw new Exception("null mailSender!");
}
if (StringUtils.isBlank(from) || StringUtils.isBlank(to)) {
throw new Exception("from and to is required!");
}
if (fileNames != null && files != null) {
if (fileNames.length != files.length) {
throw new Exception("File parameter error!");
}
}
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true, Constants.BASE_ENCODING);
helper.setFrom(from);
helper.setTo(to.endsWith(";") ? to.substring(0, to.length() - 1) : to);
helper.setSubject(subject);
helper.setText(text, true);
if (null != cc && cc.length > 0) {
helper.setCc(cc);
}
if (null != bcc && bcc.length > 0) {
helper.setBcc(bcc);
}
for (int i = 0; fileNames != null && i < fileNames.length; i++) {
helper.addAttachment(fileNames[i], files[i]);
}
mailSender.send(message);
}
use of org.springframework.mail.MailException in project bitcampSCOpen2017 by ryuyj.
the class MimeMessageInlineTest method sendMail.
@Override
public void sendMail(Member member) {
MimeMessage message = mailSender.createMimeMessage();
try {
MimeMessageHelper messageHelper = new MimeMessageHelper(message, true, "UTF-8");
messageHelper.setSubject("[공지] 회원 가입 안내");
String htmlContent = "<strong>안녕하세요</strong>, 반갑습니다." + "<img src=\"cid:logo.png\">";
messageHelper.setText(htmlContent, true);
messageHelper.setFrom("noreply@localhost.com", "로컬");
messageHelper.setTo(new InternetAddress(member.getEmail(), member.getName(), "UTF-8"));
DataSource dataSource = new FileDataSource("C:\\Users\\403room-23\\Desktop\\ddd.png");
messageHelper.addInline("logo.png", dataSource);
mailSender.send(message);
} catch (MailException e) {
e.printStackTrace();
return;
} catch (Throwable e) {
e.printStackTrace();
return;
}
}
use of org.springframework.mail.MailException in project bitcampSCOpen2017 by ryuyj.
the class SimpleRegistrationNotifier method sendMail.
public void sendMail(String memberemail) {
SimpleMailMessage message = new SimpleMailMessage();
message.setSubject("[Simple] 회원 가입 안내");
message.setFrom("isisncorp@gmail.com");
message.setText("회원 가입을 환영합니다.");
message.setTo(memberemail);
try {
mailSender.send(message);
} catch (MailException ex) {
ex.printStackTrace();
}
}
use of org.springframework.mail.MailException in project java-examples by urvanov-ru.
the class App method main.
public static void main(String[] args) {
try (GenericXmlApplicationContext context = new GenericXmlApplicationContext()) {
context.load("classpath:applicationContext.xml");
context.refresh();
JavaMailSender mailSender = context.getBean("mailSender", JavaMailSender.class);
SimpleMailMessage templateMessage = context.getBean("templateMessage", SimpleMailMessage.class);
// Создаём потокобезопасную копию шаблона.
SimpleMailMessage mailMessage = new SimpleMailMessage(templateMessage);
// TODO: Сюда напишите свой e-mail получателя.
mailMessage.setTo("ouhb93u4hng9hndf9@mail.ru");
mailMessage.setText("Привет, товарищи. Присылаю вам письмо...");
try {
mailSender.send(mailMessage);
System.out.println("Mail sended");
} catch (MailException mailException) {
System.out.println("Mail send failed.");
mailException.printStackTrace();
}
}
}
use of org.springframework.mail.MailException in project trainning by fernandotomasio.
the class SystemServiceSimpleImpl method sendMail.
@Override
@Transactional
public void sendMail(String to, String subject, String text) {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("sgc@decea.intraer");
message.setTo(to);
message.setSubject(subject);
message.setText(text);
if (to != null) {
try {
mailSender.send(message);
} catch (MailException e) {
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, e);
}
}
}
Aggregations