I followed this post Sending Email in Android using JavaMail API without using the default/built-in app to send mails without intents. it works ok. but my question is if you can send mail without having to enter your user and password? thanks

有帮助吗?

解决方案

No you can't

As you can see from the code, The username and password is used to login to that mail ID and then that Email ID is used to send the Email

The GMailSender has a constructor that takes in the username and password, this is used to create a login session as in code

session = Session.getDefaultInstance(props, this); 

Once the login has been done now your sending the Email from that mail ID as you normally do in browser

Alternatives

Now if you want to send a email then you can send an intent in android like this

    Intent email = new Intent(Intent.ACTION_SEND);
    email.putExtra(Intent.EXTRA_EMAIL, new String[]{"youremail@gmail.com"});          
    email.putExtra(Intent.EXTRA_SUBJECT, "subject");
    email.putExtra(Intent.EXTRA_TEXT, "message");
    email.setType("message/rfc822");
    startActivity(Intent.createChooser(email, "Choose an Email client"));

But this would pop up the user with the choice of client from which email has to be sent

OR

If you even dont want to use this, then I would suggest creating your own webserver and make HTTP request to it to send Emails via the server

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top