0

Hi I am creating an app(consider it as a security app) in which on clicking on button the contact list should open and by selecting a contact the mail should directly get sent to selected contact's mail address without showing pop up for asking "choose email client". i.e. I want to send mail in background. for example If you are aware of Pandora Radio app. In that you can share the station by selecting email id from contact which sends email to selected contact in background by using default email id of adnroid phone and shows a toast "station shared" after success.

I don't want to ask user for its gmail password or anything else . I managed to get even android phone default email id and by selecting contact I can get email id of selected contact I dont't want to use JavaMail beacuse it needs hardcoded email id and password. I did a lot of search but did not found solution as I want. please suggest any solution.

shankey
  • 333
  • 2
  • 7
  • 18
  • http://stackoverflow.com/questions/8614844/email-sent-without-putting-the-password-into-the-code/8614904#8614904 – Yury Dec 27 '11 at 16:16

2 Answers2

0

Try this on android 4+

public synchronized void sendMail(final String subject, final String body,
            final String sender, final String recipients) throws Exception {
        try {
            Thread mailThread = new Thread() {
                @Override
                public void run() {
                    try {
                        MimeMessage message = new MimeMessage(session);
                        DataHandler handler = new DataHandler(
                                new ByteArrayDataSource(body.getBytes(),
                                        "text/plain"));
                        message.setSender(new InternetAddress(sender));
                        message.setSubject(subject);
                        message.setDataHandler(handler);
                        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) {

                    }
                }

            };
            mailThread.start();
        } catch (Exception ex) {

        }
    }
Ryhan
  • 1,815
  • 1
  • 18
  • 22
0

Sorry, that's not supported in android SDK.

Vineet Shukla
  • 23,865
  • 10
  • 55
  • 63