我打算不使用javamail API。我打算通过SSLSocket发送消息。我已建立安全的SSL / TLS连接。但是如何在不导入javax.mail的情况下创建MIME对象。*;包以便通过套接字发送
protected static MimeMessage attach() throws IOException, MessagingException {
Properties properties = System.getProperties();
Session session = Session.getDefaultInstance(properties,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(from, password);
}
});
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(messageSubject);
BodyPart messageBodyPart1 = new MimeBodyPart();
messageBodyPart1.setText(messageBody);
MimeBodyPart messageBodyPart2 = new MimeBodyPart();
String filename = attPath;
DataSource source = new FileDataSource(filename);
messageBodyPart2.setDataHandler(new DataHandler(source));
messageBodyPart2.setFileName(filename);
Multipart multipart = new MimeMultipart();
MimeBodyPart messageBodyPart3 = new MimeBodyPart();
messageBodyPart3.setText("\nBye");
//ATTACH 3 BODY PARTS
multipart.addBodyPart(messageBodyPart1);
multipart.addBodyPart(messageBodyPart2);
multipart.addBodyPart(messageBodyPart3);
message.setContent(multipart);
return message;
}