Ich weis bereits, wie man mit JavaMail Anhänge mit einer Mail versendet. Jedoch, da dies, v.a. bei einer schlechten Internetleitung, sehr lange dauern kann, wenn man mehrere Dateien angehängt hat, möchte ich die Anhänge schon vorher hochladen - damit der Vorgang des Sendens nicht so ewig dauert. Ist dies generell mit JavaMail möglich, wenn ja, wie?
Hier noch ein bischen Code, wie ich das bisher gemacht habe:
Hoffentlich findet jemand ne Lösung!!!
Danke für eure Beiträge.
Hier noch ein bischen Code, wie ich das bisher gemacht habe:
Java:
public void login(final String username, final String password) throws Exception {
MailTool.this.username = username;
MailTool.this.password = password;
Properties props1=new Properties();
props1.put("mail.smtp.port", "587");
props1.put("mail.smtp.auth", "true");
props1.put("mail.smtp.starttls.enable", "true");
session1 = Session.getInstance(props1);
transport = session1.getTransport("smtp");
transport.connect("smtp.googlemail.com", username, password);
Properties props2 = System.getProperties();
props2.setProperty("mail.store.protocol", "imaps");
props2.setProperty("mail.imaps.partialfetch", "false");
props2.setProperty("mail.imap.host", "imap.gmail.com");
props2.setProperty("mail.imap.port", "993");
props2.setProperty("mail.imap.connectiontimeout", "5000");
props2.setProperty("mail.imap.timeout", "5000");
Session session2 = Session.getDefaultInstance(props2, null);
store = session2.getStore("imaps");
store.connect("imap.gmail.com", username, password);
folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
}
public void sendMail(String recipientAddresses, String subject, String mailText, ArrayList<File> filelist) throws Exception {
login(username, password);
Address[] addresses = InternetAddress.parse(recipientAddresses);
Message message = new MimeMessage(session1);
message.setFrom(new InternetAddress(username));
message.setRecipients(Message.RecipientType.TO, addresses);
message.setSubject(subject);
// create the message part
Multipart multipart = new MimeMultipart();
MimeBodyPart textBodyPart = new MimeBodyPart();
textBodyPart.setText(mailText);
multipart.addBodyPart(textBodyPart);
for(int i=0; i<filelist.size(); i++) {
MimeBodyPart attachementBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(filelist.get(i));
attachementBodyPart.setDataHandler(new DataHandler(source));
attachementBodyPart.setFileName(filelist.get(i).getName());
multipart.addBodyPart(attachementBodyPart);
}
message.setContent(multipart);
transport.sendMessage(message, addresses);
transport.close();
}
Hoffentlich findet jemand ne Lösung!!!
Danke für eure Beiträge.