Я не могу прикрепить файл к вложению.
ERROR: IOException while sending message
Без вложений отправляет отлично, я проверяю File.exists () true
Я перепробовал много методов.Не один не работает.Тот же результат
...
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", mailhost);
props.put("mail.smtp.port", port);
props.put("mail.smtp.ssl.enable", "true");
props.put("mail.smtp.auth", "true");
Session session = Session.getInstance(props);
MimeMessage msg = new MimeMessage(session);
Multipart multipart = new MimeMultipart();
Transport transport = session.getTransport();
msg.setSender(new InternetAddress(sender));
msg.setSubject(subject);
MimeBodyPart part = new MimeBodyPart();
part.setText(body);
String file = new String("/sdcard/DCIM/2.jpg");
FileDataSource fileDataSource = new FileDataSource(file);
MimeBodyPart attachmentPart = new MimeBodyPart();
attachmentPart.setDataHandler(new DataHandler(fileDataSource));
attachmentPart.setFileName(fileDataSource.getName());
if (new File(file).exists()) Log.e("sendMail", "file exists");
multipart.addBodyPart(part);
multipart.addBodyPart(attachmentPart);
msg.setContent(multipart);
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
transport.connect(mailhost, username, password);
transport.sendMessage(msg, msg.getAllRecipients());
решен проблема с разрешениями для Android и
attachmentPart.setHeader("Content-Type", "application/octet-stream");
image / jpeg smtp сервер жалуется на спам :)