-1

I'm having an issue similar to this: Adding text from edit text field into an email . I am able to do what this is doing, but how could I send the email straight from a submit button, instead of having it compose an email in a default email client. This should be able to be sent with as anonymous and not need to be sent by default from an installed email client.

Community
  • 1
  • 1

3 Answers3

1

You need to download JavaMail API: Download: https://java.net/projects/javamail/pages/Home

You need an SMTP server, also username and password for auth.

          String host="your smtp";
          final String user="from email address";//change accordingly
          final String password="frm email password";//change accordingly

          String to="to email";//change accordingly

           //Get the session object
           Properties props = new Properties();
           props.put("mail.smtp.host",host);
           props.put("mail.smtp.auth", "true");

           javax.mail.Session session = javax.mail.Session.getDefaultInstance(props,new javax.mail.Authenticator() {
                      protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
                    return new javax.mail.PasswordAuthentication(user,password);
                      }
                    });

                   //Compose the message
                    try {
                     MimeMessage message = new MimeMessage(session);
                     message.setFrom(new InternetAddress(user));
                     message.addRecipient(javax.mail.Message.RecipientType.TO,new InternetAddress(to));
                     message.setSubject("javatpoint");
                     message.setText("This is simple program of sending email using JavaMail API");

                    //send the message
                     javax.mail.Transport.send(message);

                     System.out.println("message sent successfully...");

                     } 
                    catch (MessagingException e) 
                    {
                        e.printStackTrace();
                        }
72DFBF5B A0DF5BE9
  • 4,954
  • 3
  • 21
  • 24
1

There is no way to send an email silently, without either

  • letting the user know and accept it first (by using intents and an email provider)
  • or asking for the username and password before and using an email API as above (the user will implicitly give you the approval to send/receive emails by entering those values)

And that is a very good thing! There are too many security concerns otherwise. If you ever find a way, please post it as a bug report in android.

Workaround: You need to use an email API such as JavaMail:

Sending Email in Android using JavaMail API without using the default/built-in app

Community
  • 1
  • 1
Dheeraj Bhaskar
  • 18,633
  • 9
  • 63
  • 66
-1

There are some anonymous mailers that have APIs that you could use. But I would suggest you not do this. I actually agree with @DheeB 100%. I can't up vote yet.

Here is an example of one such service: http://api.temp-mail.ru/ It's in Russian but it can be translated. Again, I don't recommend but trying to answer your question.

Shy Ward
  • 41
  • 4