I'm trying to do it in this way, but I can't get it running.
The email is sent, but the file is not attached to the email.
private boolean sendMailWithAttachmentTXT(){
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
try {
StringBuffer buff = new StringBuffer();
buff.append("Hello \n");
buff.append("world! ");
Message msg = new MimeMessage(session);
String htmlBody = "This is <b> html </b>"; // ...
Multipart mp = new MimeMultipart();
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent(htmlBody, "text/html");
DataSource src = new ByteArrayDataSource(new
ByteArrayInputStream(buff.toString().getBytes()), "text/plain");
MimeBodyPart attachment = new MimeBodyPart();
attachment.setFileName("text.txt");
attachment.setDataHandler(new DataHandler(src));
//put the parts together into a multipart
mp.addBodyPart(htmlPart);
mp.addBodyPart(attachment);
msg.setContent(mp);
msg.setFrom(new InternetAddress("[email protected]"));
msg.addRecipient(Message.RecipientType.TO, new
InternetAddress("[email protected]", "Me"));
msg.setSubject("TXT Attached");
msg.saveChanges();
Transport.send(msg);
return true;
} catch (AddressException e) {
e.printStackTrace();
logger.warning("AddressException: " + e.getMessage());
} catch (MessagingException e) {
e.printStackTrace();
logger.warning("MessagingException: " + e.getMessage());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
logger.warning("UnsupportedEncodingException: " +
e.getMessage());
} catch (IOException e) {
e.printStackTrace();
logger.warning("IOException: " + e.getMessage());
}
return false;
}
BTW, I am excuting this log on appengine and I don't get any log message.
What I am missing?
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.