0

I'm looking for a library to access Gmail which can handle attachments. Can someone point me towards this please?

Thanks

Rubén
  • 34,714
  • 9
  • 70
  • 166
govule
  • 63
  • 1
  • 6
  • there is a javax mail port for Android. For an example and references, read this other [answer](http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-android-a/2033124#2033124). – espinielli Feb 18 '12 at 11:06

2 Answers2

2

This link might be helpful.....

http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android

make changes in sendMail section for attachment..

    public synchronized void sendMail(String subject, String body, String sender, String recipients, File attachment) throws Exception {
    try{
    MimeMessage message = new MimeMessage(session);
    message.setSender(new InternetAddress(sender));
    message.setSubject(subject);MimeBodyPart mbp1 = new MimeBodyPart();
    mbp1.setText(body);

    MimeBodyPart mbp2 = new MimeBodyPart();
    FileDataSource fds = new FileDataSource(attachment);
    mbp2.setDataHandler(new DataHandler(fds));
    mbp2.setFileName(fds.getName());

    Multipart mp = new MimeMultipart();
    mp.addBodyPart(mbp1);
    mp.addBodyPart(mbp2);

    message.setContent(mp);

    if (recipients.indexOf(',') > 0)
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
    else
        message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
    Transport.send(message);
    }catch(Exception e){

    }
}`
rjn123
  • 27
  • 8
0

Gmail has an Oauth protocol for accessing IMAP and SMTP. You can read more about it here, including samples: http://code.google.com/apis/gmail/oauth/code.html

Juliana Peña
  • 864
  • 9
  • 21