I am trying to send an e-mail which contains an attachment (an image) to my facebook account (used to post this image on my page's wall).
The e-mail sent perfectly but nothing is shown on my wall.
If I send it directly through Gmail, it works perfectly. What I am doing wrong ?
Here is my code :
private static final String HOST = "smtp.gmail.com";
private static final String USERNAME = "myusername"; // Without @gmail.com
private static final String PASSWORD = "mypassword";
private static final Properties PARAMETERS = new Properties() {
private static final long serialVersionUID = 1L; {
put("mail.smtp.starttls.enable", "true");
put("mail.smtp.host", HOST);
put("mail.smtp.user", USERNAME);
put("mail.smtp.password", PASSWORD);
put("mail.smtp.port", "587");
put("mail.smtp.auth", "true");
}
};
// Some code...
final File newest = new File(COMICS_DIR, COMICS_DIR.list().length - 1 + ".png"); // The file I want to upload.
final Session session = Session.getInstance(PARAMETERS);
final MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(USERNAME));
message.addRecipient(RecipientType.TO, new InternetAddress(FACEBOOK_MAIL)); // My facebook mail.
message.setSubject(title);
final Multipart multipart = new MimeMultipart();
final BodyPart body = new MimeBodyPart();
body.setDataHandler(new DataHandler(new FileDataSource(newest)));
body.setFileName(newest.getName());
multipart.addBodyPart(body);
message.setContent(multipart);
final Transport transport = session.getTransport("smtp");
transport.connect(HOST, USERNAME, PASSWORD);
transport.sendMessage(message, message.getAllRecipients());
Thanks for your time and sorry for my bad english.
EDIT : I have the same error for Tumblr but it works for Twitpics.
Try this:
Replace
final Multipart multipart = new MimeMultipart();
final BodyPart body = new MimeBodyPart();
body.setDataHandler(new DataHandler(new FileDataSource(newest)));
body.setFileName(newest.getName());
multipart.addBodyPart(body);
message.setContent(multipart);
with
final Multipart multipart = new MimeMultipart();
multipart.setDataHandler(new DataHandler(new FileDataSource(newest)));
multipart.setDisposition(Part.ATTACHMENT);
multipart.setFileName(newest.getName());
message.setContent(multipart);
message.saveChanges();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.