use of org.springframework.mail.javamail.MimeMessageHelper 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("bit@gmail.com", "비트");
// 받는사람 설정
helper.setTo(new InternetAddress(member.getMember_id(), member.getMember_name(), "UTF-8"));
// 첨부파일 설정
DataSource dataSource = new FileDataSource("d:\\1300.jpg");
helper.addAttachment(MimeUtility.encodeText("다스.jpg", "UTF-8", "B"), dataSource);
mailSender.send(message);
} catch (MessagingException | UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.springframework.mail.javamail.MimeMessageHelper 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.javamail.MimeMessageHelper in project spring-integration-samples by spring-projects.
the class MimeMessageParsingTest method testProcessingOfEmailAttachments.
/**
* This test will create a Mime Message that contains an Attachment, send it
* to an SMTP Server (Using Wiser) and retrieve and process the Mime Message.
*
* This test verifies that the parsing of the retrieved Mime Message is
* successful and that the correct number of {@link EmailFragment}s is created.
*/
@Test
public void testProcessingOfEmailAttachments() {
final JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setPort(this.wiserPort);
final MimeMessage message = mailSender.createMimeMessage();
final String pictureName = "picture.png";
final ByteArrayResource byteArrayResource = getFileData(pictureName);
try {
final MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom("testfrom@springintegration.org");
helper.setTo("testto@springintegration.org");
helper.setSubject("Parsing of Attachments");
helper.setText("Spring Integration Rocks!");
helper.addAttachment(pictureName, byteArrayResource, "image/png");
} catch (MessagingException e) {
throw new MailParseException(e);
}
mailSender.send(message);
final List<WiserMessage> wiserMessages = wiser.getMessages();
Assert.assertTrue(wiserMessages.size() == 1);
boolean foundTextMessage = false;
boolean foundPicture = false;
for (WiserMessage wiserMessage : wiserMessages) {
final List<EmailFragment> emailFragments = new ArrayList<EmailFragment>();
try {
final MimeMessage mailMessage = wiserMessage.getMimeMessage();
EmailParserUtils.handleMessage(null, mailMessage, emailFragments);
} catch (MessagingException e) {
throw new IllegalStateException("Error while retrieving Mime Message.");
}
Assert.assertTrue(emailFragments.size() == 2);
for (EmailFragment emailFragment : emailFragments) {
if ("picture.png".equals(emailFragment.getFilename())) {
foundPicture = true;
}
if ("message.txt".equals(emailFragment.getFilename())) {
foundTextMessage = true;
}
}
Assert.assertTrue(foundPicture);
Assert.assertTrue(foundTextMessage);
}
}
use of org.springframework.mail.javamail.MimeMessageHelper in project jhipster-sample-app-websocket by jhipster.
the class MailService method sendEmail.
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}", isMultipart, isHtml, to, subject, content);
// Prepare message using a Spring helper
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, StandardCharsets.UTF_8.name());
message.setTo(to);
message.setFrom(jHipsterProperties.getMail().getFrom());
message.setSubject(subject);
message.setText(content, isHtml);
javaMailSender.send(mimeMessage);
log.debug("Sent email to User '{}'", to);
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.warn("Email could not be sent to user '{}'", to, e);
} else {
log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
}
}
}
use of org.springframework.mail.javamail.MimeMessageHelper in project jhipster-sample-app-hazelcast by jhipster.
the class MailService method sendEmail.
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}", isMultipart, isHtml, to, subject, content);
// Prepare message using a Spring helper
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, StandardCharsets.UTF_8.name());
message.setTo(to);
message.setFrom(jHipsterProperties.getMail().getFrom());
message.setSubject(subject);
message.setText(content, isHtml);
javaMailSender.send(mimeMessage);
log.debug("Sent email to User '{}'", to);
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.warn("Email could not be sent to user '{}'", to, e);
} else {
log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
}
}
}
Aggregations