A
annie
Gast
Halllo zusammen,
ich habe folgt ein Code programmiert. Jetzt will ich aus einer Datei alles auslesen und den Inhalt in einer Email versenden.
Leider klappt dies nicht, er schreib mir immer nur die letzte Zeile in meine Email.... kann mir jemand helfen?
Grüße Annie
ich habe folgt ein Code programmiert. Jetzt will ich aus einer Datei alles auslesen und den Inhalt in einer Email versenden.
Leider klappt dies nicht, er schreib mir immer nur die letzte Zeile in meine Email.... kann mir jemand helfen?
Grüße Annie
Java:
private static void sendMail(String order) throws NoSuchProviderException,
MessagingException, AddressException, IOException {
Properties props = new Properties();
Session session = Session.getDefaultInstance(props);
session.setDebug(false);
Transport tr = session.getTransport(new URLName(TYPE, HOST, PORT, null, null, null));
// USER, PASSWD));
Message message = new MimeMessage(session);
message.addRecipient(RecipientType.TO, new InternetAddress(RECIPIENT));
message.addFrom(new InternetAddress[] { new InternetAddress(SENDER) });
// subject
message.setSubject("Bestellung: " + order);
// the multipart
BufferedReader br = new BufferedReader(new FileReader(new File("H:/i/r/txt/", order + ".txt")));
String line;
List<String> lines = new ArrayList<String>();
MimeMultipart multiPart = new MimeMultipart("mixed");
MimeBodyPart bodypart = new MimeBodyPart();
while ((line = br.readLine()) != null) {
bodypart.setContent(line, "text/plain");
multiPart.addBodyPart(bodypart);
}
MimeBodyPart body3 = new MimeBodyPart();
body3.attachFile(new File("H:/i/txt/", order + ".txt"));
multiPart.addBodyPart(body3);
// set the content to the multipart
message.setContent(multiPart);
// send
tr.connect();
tr.sendMessage(message, message.getAllRecipients());
tr.close();
}