use of fi.otavanopisto.muikku.mail.MailAttachment in project muikku by otavanopisto.
the class DummyMailBridge method sendMail.
@Override
public void sendMail(MailType mimeType, String from, List<String> to, List<String> cc, List<String> bcc, String subject, String content, List<MailAttachment> attachments) {
StringBuilder message = new StringBuilder();
message.append("DUMMY MAIL: Type: ");
message.append(mimeType.toString());
message.append(" From: ");
message.append(from);
message.append(" To: ");
for (String email : to) {
message.append(email);
message.append(" ");
}
message.append("CC: ");
for (String email : cc) {
message.append(email);
message.append(" ");
}
message.append("BCC: ");
for (String email : bcc) {
message.append(email);
message.append(" ");
}
message.append("Subject: ");
message.append(subject);
message.append("Content: ");
message.append(content);
message.append(" Attachments: ");
for (MailAttachment attachment : attachments) {
message.append(attachment.toString());
message.append(" ");
}
logger.log(Level.INFO, message.toString());
}
use of fi.otavanopisto.muikku.mail.MailAttachment in project muikku by otavanopisto.
the class JndiMailService method onMailEvent.
@Asynchronous
@Lock(LockType.READ)
public void onMailEvent(@Observes JndiMailEvent event) {
try {
MailType mimeType = event.getMimeType();
String from = event.getFrom();
List<String> to = event.getTo();
List<String> cc = event.getCc();
List<String> bcc = event.getBcc();
String subject = event.getSubject();
String content = event.getContent();
List<MailAttachment> attachments = event.getAttachments();
Properties props = new Properties();
InitialContext initialContext = new InitialContext(props);
Session mailSession = (Session) initialContext.lookup("java:/mail/muikku");
MimeMessage message = new MimeMessage(mailSession);
if (!to.isEmpty()) {
message.setRecipients(Message.RecipientType.TO, parseToAddressArray(to));
}
if (!cc.isEmpty()) {
message.setRecipients(Message.RecipientType.CC, parseToAddressArray(cc));
}
if (!bcc.isEmpty()) {
message.setRecipients(Message.RecipientType.BCC, parseToAddressArray(bcc));
}
if (from != null) {
InternetAddress fromAddress = new InternetAddress(from);
message.setFrom(fromAddress);
message.setReplyTo(new InternetAddress[] { fromAddress });
}
if (subject != null) {
message.setSubject(subject);
}
message.setSentDate(new Date());
if (!attachments.isEmpty()) {
Multipart multipart = new MimeMultipart();
if (content != null) {
MimeBodyPart contentBodyPart = new MimeBodyPart();
contentBodyPart.setContent(content, mimeType.toString());
multipart.addBodyPart(contentBodyPart);
}
for (MailAttachment attachment : attachments) {
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
attachmentBodyPart.setContent(attachment.getContent(), attachment.getMimeType());
attachmentBodyPart.setFileName(attachment.getFileName());
multipart.addBodyPart(attachmentBodyPart);
}
message.setContent(multipart);
} else {
if (content != null) {
message.setContent(content, mimeType.toString());
}
}
// Sending
Transport.send(message);
} catch (Exception e) {
logger.log(Level.SEVERE, "Error sending mail", e);
}
}
Aggregations