Search in sources :

Example 21 with MailException

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);
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) MailException(org.springframework.mail.MailException)

Example 22 with MailException

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;
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MimeMessage(javax.mail.internet.MimeMessage) FileDataSource(javax.activation.FileDataSource) MailException(org.springframework.mail.MailException) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) FileDataSource(javax.activation.FileDataSource) DataSource(javax.activation.DataSource)

Example 23 with MailException

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();
    }
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MailException(org.springframework.mail.MailException)

Example 24 with MailException

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();
        }
    }
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MailException(org.springframework.mail.MailException) JavaMailSender(org.springframework.mail.javamail.JavaMailSender) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext)

Example 25 with MailException

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);
        }
    }
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MailException(org.springframework.mail.MailException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

MailException (org.springframework.mail.MailException)47 MimeMessage (javax.mail.internet.MimeMessage)18 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)17 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)15 MessagingException (javax.mail.MessagingException)10 Date (java.util.Date)8 Properties (java.util.Properties)3 InternetAddress (javax.mail.internet.InternetAddress)3 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)3 JavaMailSender (org.springframework.mail.javamail.JavaMailSender)3 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 AuthenticationFailedException (jakarta.mail.AuthenticationFailedException)2 MessagingException (jakarta.mail.MessagingException)2 NoSuchProviderException (jakarta.mail.NoSuchProviderException)2 MimeMessage (jakarta.mail.internet.MimeMessage)2 PrintWriter (java.io.PrintWriter)2 URI (java.net.URI)2 Matcher (java.util.regex.Matcher)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 MolgenisDataException (org.molgenis.data.MolgenisDataException)2