错误:javax.mail.AuthenticationFailedException

时间:2017-12-01 12:08:31

标签: java android email javamail

我正在尝试在没有用户互动的情况下发送电子邮件,我正在参考This site 但我得到以下异常

  

javax.mail.AuthenticationFailedException

我尝试了许多解决方案,例如thisthis以及许多其他解决方案,但没有任何反应 以下是我的活动代码:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button addImage =  findViewById(R.id.button);
        addImage.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                new SendMail().execute("");
            }
        });
    }
    private class SendMail extends AsyncTask<String, Integer, Void> {

        private ProgressDialog progressDialog;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            progressDialog = ProgressDialog.show(MainActivity.this, "Please wait", "Sending mail", true, false);
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);
            progressDialog.dismiss();
        }

        protected Void doInBackground(String... params) {
            Mail m = new Mail("saifali.webappmate@gmail", "**********");

            String[] toArr = {"shashwat.webappmate@gmail", "saifali.webappmate@gmail"};
            m.setTo(toArr);
            m.setFrom("saifali.webappmate@gmail.com");
            m.setSubject("This is an email sent using my Mail JavaMail wrapper from an Android device.");
            m.setBody("Email body.");

            try {
                if(m.send()) {
                    Toast.makeText(MainActivity.this, "Email was sent successfully.", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(MainActivity.this, "Email was not sent.", Toast.LENGTH_LONG).show();
                }
            } catch(Exception e) {
                Log.e("MailApp", "Could not send email", e);
            }
            return null;
        }
    }

如果有人有任何更好的解决方案,请建议我。 感谢。

0 个答案:

没有答案