Ich habe eine Methode erstellt, um eine Mail mit Java-GUI mit mehreren Dateien Anhänge zu senden. Wenn die Methode die E-Mail sendet, werden Anhangsdateien wie Microsoft Office und PDF an die empfangende E-Mail als BitSarver gesendet. Ich muss Datei senden, um dort zu schreiben, also kann anderes automatisches System arbeiten, indem er die Anlagedatei liest und sie druckt.JavaMail schickte BitSarver-Datei und keine PDF-Datei
Dies ist die Methode.
static public boolean sendMail(String to,String subject,String text_filed)
{
Properties props = new Properties();
props.put("mail.smtp.host","smtp.gmail.com");
props.put("mail.smtp.socketFactory.port ","465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth","true");
props.put("mail.smtp.port","465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator(){
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("eamil", pass);
}
}
);
try
{
Message m = new MimeMessage(session);
m.setFrom(new InternetAddress(userMAil));
System.out.println("from "+userMAil);
m.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
System.out.println("to "+to);
m.setSubject(subject);
System.out.println("the subject "+subject);
MimeBodyPart bodypart = new MimeBodyPart();
bodypart.setText(text_filed);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(bodypart);
System.out.println("the content "+text_filed);
for(int i = 0;i< main_controller.attachments_path.size();i++)
{
bodypart = new MimeBodyPart();
DataSource source = new FileDataSource(main_controller.attachments_path.get(i));
System.out.println("the file location"+main_controller.attachments_path.get(i));
bodypart.setDataHandler(new DataHandler(source));
//bodypart.setFileName(main_controller.filesFrame.getFilename());
System.out.println("the file name"+main_controller.filesFrame.getFilename());
multipart.addBodyPart(bodypart);
}
m.setContent(multipart);
//m.setText(text_filed);
Transport.send(m);
JOptionPane.showMessageDialog(null, "done!");
return true;
}
catch(Exception e)
{
String m = e.getMessage();
JOptionPane.showMessageDialog(null, e);
System.out.println(m);
return false;
}
}
hoffen, dass Sie mir helfen können: D
Ich habe versucht, aber ich bekomme immer noch das gleiche Ergebnis 'm.saveChanges(); m.setContent (mehrteilig); Transport.send (m); ' –