Search in sources :

Example 46 with DataSource

use of javax.activation.DataSource in project iaf by ibissource.

the class MailSender method decodeBase64.

private DataHandler decodeBase64(String str) {
    byte[] bytesDecoded = Base64.decode(str);
    String encodingType = "application/octet-stream";
    DataSource ads = new ByteArrayDataSource(bytesDecoded, encodingType);
    return new DataHandler(ads);
}
Also used : DataHandler(javax.activation.DataHandler) ByteArrayDataSource(org.apache.soap.util.mime.ByteArrayDataSource) URLDataSource(javax.activation.URLDataSource) ByteArrayDataSource(org.apache.soap.util.mime.ByteArrayDataSource) DataSource(javax.activation.DataSource)

Example 47 with DataSource

use of javax.activation.DataSource in project activityinfo by bedatadriven.

the class SmtpMailSender method send.

@Override
public void send(Message message) {
    try {
        Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);
        MimeMessage mimeMessage = new MimeMessage(session);
        mimeMessage.setSubject(message.getSubject(), Charsets.UTF_8.name());
        mimeMessage.addRecipients(RecipientType.TO, toArray(message.getTo()));
        mimeMessage.addRecipients(RecipientType.BCC, toArray(message.getBcc()));
        mimeMessage.setFrom(new InternetAddress(configuration.getProperty("smtp.from", "activityinfo@configure-me.com"), configuration.getProperty("smtp.from.name", "ActivityInfo")));
        if (message.getReplyTo() != null) {
            mimeMessage.setReplyTo(new Address[] { message.getReplyTo() });
        }
        String body;
        if (message.hasHtmlBody()) {
            body = message.getHtmlBody();
            mimeMessage.setDataHandler(new DataHandler(new HTMLDataSource(body)));
        } else {
            body = message.getTextBody();
            mimeMessage.setText(body, Charsets.UTF_8.name());
        }
        LOGGER.finest("message to " + message.getTo() + ":\n" + body);
        if (!message.getAttachments().isEmpty()) {
            Multipart multipart = new MimeMultipart();
            for (MessageAttachment attachment : message.getAttachments()) {
                MimeBodyPart part = new MimeBodyPart();
                part.setFileName(attachment.getFilename());
                DataSource src = new ByteArrayDataSource(attachment.getContent(), attachment.getContentType());
                part.setDataHandler(new DataHandler(src));
                multipart.addBodyPart(part);
            }
            mimeMessage.setContent(multipart);
        }
        mimeMessage.saveChanges();
        Transport.send(mimeMessage);
    } catch (MessagingException | UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MimeMultipart(javax.mail.internet.MimeMultipart) DataHandler(javax.activation.DataHandler) Properties(java.util.Properties) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) DataSource(javax.activation.DataSource) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) MimeBodyPart(javax.mail.internet.MimeBodyPart) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource)

Example 48 with DataSource

use of javax.activation.DataSource in project bitcampSCOpen2017 by ryuyj.

the class MimeMessageHelperFileTest 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>, 반갑습니다.";
        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\\hi.doc");
        messageHelper.addAttachment(MimeUtility.encodeText("hi.doc", "UTF-8", "B"), 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 49 with DataSource

use of javax.activation.DataSource in project bitcampSCOpen2017 by ryuyj.

the class SimpleRegistrationNotifier2 method sendMailAttach.

public void sendMailAttach(Member member) {
    MimeMessage message = mailSender.createMimeMessage();
    try {
        // 메일에 파일 첨부를 위해서 MimeMessageHelper 클래스 이용,
        // 생성자 매개변수 (메시지, 파일 첨부여부, 인코딩)
        MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
        // 제목설정
        helper.setSubject("회원가입");
        // 내용설정
        String htmlContent = "<strong>안녕하세요</strong>, 반갑습니다.";
        helper.setText(htmlContent, true);
        // 보내는 사람 설정
        helper.setFrom("bpppys@gmail.com", "git");
        // 받는 사람 설정
        helper.setTo(new InternetAddress(member.getMember_id(), member.getMember_name(), "UTF-8"));
        // 첨부파일 설정
        DataSource dataSource = new FileDataSource("d:\\100.jpg");
        helper.addAttachment(MimeUtility.encodeText("이미지.jpg", "UTF-8", "B"), dataSource);
        mailSender.send(message);
    } catch (MessagingException | UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) FileDataSource(javax.activation.FileDataSource) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) FileDataSource(javax.activation.FileDataSource) DataSource(javax.activation.DataSource)

Example 50 with DataSource

use of javax.activation.DataSource in project tesb-rt-se by Talend.

the class MailSender method createMultipart.

private Multipart createMultipart(String message, URL attachment) throws MessagingException {
    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setText(message);
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);
    messageBodyPart = new MimeBodyPart();
    DataSource source = new URLDataSource(attachment);
    messageBodyPart.setDataHandler(new DataHandler(source));
    multipart.addBodyPart(messageBodyPart);
    return multipart;
}
Also used : MimeBodyPart(javax.mail.internet.MimeBodyPart) BodyPart(javax.mail.BodyPart) MimeMultipart(javax.mail.internet.MimeMultipart) Multipart(javax.mail.Multipart) URLDataSource(javax.activation.URLDataSource) MimeMultipart(javax.mail.internet.MimeMultipart) DataHandler(javax.activation.DataHandler) MimeBodyPart(javax.mail.internet.MimeBodyPart) URLDataSource(javax.activation.URLDataSource) DataSource(javax.activation.DataSource)

Aggregations

DataSource (javax.activation.DataSource)196 DataHandler (javax.activation.DataHandler)114 FileDataSource (javax.activation.FileDataSource)60 MimeBodyPart (javax.mail.internet.MimeBodyPart)53 MimeMultipart (javax.mail.internet.MimeMultipart)48 MimeMessage (javax.mail.internet.MimeMessage)39 InputStream (java.io.InputStream)37 IOException (java.io.IOException)36 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)35 ByteArrayInputStream (java.io.ByteArrayInputStream)33 File (java.io.File)33 ByteArrayOutputStream (java.io.ByteArrayOutputStream)30 Test (org.junit.Test)30 InternetAddress (javax.mail.internet.InternetAddress)27 Properties (java.util.Properties)26 MessagingException (javax.mail.MessagingException)25 Multipart (javax.mail.Multipart)24 Session (javax.mail.Session)21 BodyPart (javax.mail.BodyPart)19 ArrayList (java.util.ArrayList)16