//
Session session = Session.getDefaultInstance(props, null);
//
// Erzeugen einer MimeMessage:
//
Message msg = new MimeMessage(session);
//
// Erzeugen der Absender-Adresse der Message:
//
InternetAddress fromAddress = new InternetAddress(from);
msg.setFrom(fromAddress);
//
// Erzeugen der Empf�nger-Adresse der Message:
//
int max = to.length;
InternetAddress[] toAddress = new InternetAddress[max];
for (int i = 0; i < max; i++) {
toAddress[i] = new InternetAddress(to[i]);
}
msg.setRecipients(Message.RecipientType.TO, toAddress);
//
// Setzen des Subjects der Message:
//
msg.setSubject(subject);
// BURMEBJ003A begin
if (attachements == null) {
//
// Setzen des Message-Contents:
//
msg.setContent(msgText, "text/plain; charset=ISO-8859-1");
}
// BURMEBJ003A end
else {
// BURMEBJ003 moved begin
//
// Erzeugen eines MimeMultipart:
//
MimeMultipart mp = new MimeMultipart();
//
// Anhängen eines MimeBodyParts für den einleitenden Text:
//
MimeBodyPart text = new MimeBodyPart();
text.setDisposition(Part.INLINE);
text.setContent(msgText, "text/plain; charset=ISO-8859-1");
mp.addBodyPart(text);
//
// Anhängen der Attachements:
//
// BURMEBJ003 moved end
// @BURMEBJ002A begin
int numberOfFileNames = 0;
if (fileNames != null) {
numberOfFileNames = fileNames.length;
}
// @BURMEBJ002A end
for (int i = 0; i < attachements.length; i++) {
MimeBodyPart file_part = new MimeBodyPart();
java.io.File file = attachements[i];
FileDataSource fds = new FileDataSource(file);
DataHandler dh = new DataHandler(fds);
// @BURMEBJ002M begin
String fileName = file.getName();
if (i < numberOfFileNames && fileNames[i] != null) {
fileName = fileNames[i];
}
file_part.setFileName(fileName);
// @BURMEBJ002M end
file_part.setDisposition(Part.ATTACHMENT);
file_part.setDescription("Attached file: " + file.getName());
file_part.setDataHandler(dh);
mp.addBodyPart(file_part);
}
msg.setContent(mp);
}
//
// Abschicken der Message:
//
Transport.send(msg);