| | |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.util; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | |
| | | import java.util.Properties; |
| | | import javax.activation.DataHandler; |
| | | import javax.activation.FileDataSource; |
| | | import javax.mail.Message; |
| | | import javax.mail.MessagingException; |
| | | import javax.mail.SendFailedException; |
| | | import javax.mail.Session; |
| | |
| | | import org.opends.server.types.DebugLogLevel; |
| | | |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import static org.opends.server.messages.MessageHandler.*; |
| | | import static org.opends.server.messages.UtilityMessages.*; |
| | | import static org.opends.messages.UtilityMessages.*; |
| | | import org.opends.messages.MessageBuilder; |
| | | |
| | | |
| | | /** |
| | |
| | | private String subject; |
| | | |
| | | // The body for the mail message. |
| | | private StringBuilder body; |
| | | private MessageBuilder body; |
| | | |
| | | |
| | | |
| | |
| | | recipients = new ArrayList<String>(); |
| | | recipients.add(recipient); |
| | | |
| | | body = new StringBuilder(); |
| | | body = new MessageBuilder(); |
| | | attachments = new LinkedList<MimeBodyPart>(); |
| | | bodyMIMEType = "text/plain"; |
| | | } |
| | |
| | | this.recipients = recipients; |
| | | this.subject = subject; |
| | | |
| | | body = new StringBuilder(); |
| | | body = new MessageBuilder(); |
| | | attachments = new LinkedList<MimeBodyPart>(); |
| | | bodyMIMEType = "text/plain"; |
| | | } |
| | |
| | | * |
| | | * @return The body for this message. |
| | | */ |
| | | public StringBuilder getBody() |
| | | public MessageBuilder getBody() |
| | | { |
| | | return body; |
| | | } |
| | |
| | | * |
| | | * @param body The body for this message. |
| | | */ |
| | | public void setBody(StringBuilder body) |
| | | public void setBody(MessageBuilder body) |
| | | { |
| | | this.body = body; |
| | | } |
| | |
| | | /** |
| | | * Specifies the body for this message. |
| | | * |
| | | * @param bodyString The body for this message. |
| | | * @param body The body for this message. |
| | | */ |
| | | public void setBody(String bodyString) |
| | | public void setBody(Message body) |
| | | { |
| | | body = new StringBuilder(bodyString); |
| | | this.body = new MessageBuilder(body); |
| | | } |
| | | |
| | | |
| | |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, me); |
| | | } |
| | | |
| | | int msgID = MSGID_EMAILMSG_INVALID_SENDER_ADDRESS; |
| | | String msg = getMessage(msgID, String.valueOf(sender), |
| | | me.getMessage()); |
| | | throw new MessagingException(msg, me); |
| | | Message msg = ERR_EMAILMSG_INVALID_SENDER_ADDRESS.get( |
| | | String.valueOf(sender), me.getMessage()); |
| | | throw new MessagingException(msg.toString(), me); |
| | | } |
| | | |
| | | |
| | |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, me); |
| | | } |
| | | |
| | | int msgID = MSGID_EMAILMSG_INVALID_RECIPIENT_ADDRESS; |
| | | String msg = getMessage(msgID, String.valueOf(recipient), |
| | | me.getMessage()); |
| | | throw new MessagingException(msg, me); |
| | | Message msg = ERR_EMAILMSG_INVALID_RECIPIENT_ADDRESS.get( |
| | | String.valueOf(recipient), me.getMessage()); |
| | | throw new MessagingException(msg.toString(), me); |
| | | } |
| | | } |
| | | message.setRecipients(Message.RecipientType.TO, recipientAddresses); |
| | | message.setRecipients( |
| | | javax.mail.Message.RecipientType.TO, |
| | | recipientAddresses); |
| | | |
| | | |
| | | // If we have any attachments, then the whole thing needs to be |
| | |
| | | // Otherwise, throw a generic exception. |
| | | if (sendException == null) |
| | | { |
| | | int msgID = MSGID_EMAILMSG_CANNOT_SEND; |
| | | String message = getMessage(msgID); |
| | | throw new MessagingException(message); |
| | | Message message = ERR_EMAILMSG_CANNOT_SEND.get(); |
| | | throw new MessagingException(message.toString()); |
| | | } |
| | | else |
| | | { |