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);
}
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);
}
}
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;
}
}
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();
}
}
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;
}
Aggregations