我正在使用以下代码向用户的电子邮件帐户发送激活码(来自网站Sending Emails without User Intervention (no Intents) in Android
http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_(no_Intents)_in_Android)。
这个想法很简单:只需使用用户的电子邮件将背景中的激活码与电子邮件一起发送回用户的电子邮件即可。
第一次按下激活按钮,一切正常,激活码在指定的电子邮件中得到很好的接收。
但是,当我从第二次开始按下激活按钮时,它只会报警“生成激活码”,但没有“激活码发送成功!\ n请在5分钟后检查电子邮件”,从而没有电子邮件收到了。
我想问一下
此类服务(smtp.gmail.com
)是否有最短时间间隔?我在5分钟后再次按下,电子邮件仍然无法发送。如果没有,如何修改代码?
除了Gmail之外的电子邮件是否可以?
如果我的应用是使用此服务发布的,那么很多用户可能会同时请求激活码,服务会不可用吗?
提前致谢!!
button_activation.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
custom_email = EditText_email.getText().toString();
custom_email_pw = EditText_email_pw.getText().toString();
if (custom_email.length()!=0 && custom_email_pw.length()!=0)
{
SharedPreferences settings = Settings.this.getSharedPreferences("MyApp",0);
SharedPreferences.Editor e = settings.edit();
e.putString("custom_email",custom_email);
e.putString("custom_email_pw",custom_email_pw);
e.commit();
SendTask sTask = new SendTask();
sTask.execute();
return;
}
class SendTask extends AsyncTask<Integer, Integer, String>
{
@Override
protected void onPreExecute()
{
Toast.makeText(Settings.this, "Generating Activation code...", Toast.LENGTH_SHORT).show();
super.onPreExecute();
}
@Override
protected String doInBackground(Integer... params)
{
{
SharedPreferences settings = Settings.this.getSharedPreferences("MyApp",0);
custom_email = settings.getString("custom_email",null);
custom_email_pw = settings.getString("custom_email_pw",null);
Looper.prepare();
Mail m = new Mail(custom_email, custom_email_pw);
String[] toArr = {custom_email};
m.set_to(toArr);
m.set_from("from@gmail.com");
m.set_subject("App: Email Activation Code");
m.set_body("The email Activation Code is 123");
try
{
if(m.send())
{
Toast.makeText(Settings.this, "Activation code sent successfully!\nPlease check email after 5 minutes.", Toast.LENGTH_LONG).show(); // success
}
else
{
Toast.makeText(Settings.this, "Activation code sending failure!", Toast.LENGTH_LONG).show(); // failure
}
}
catch(Exception e)
{
Toast.makeText(Settings.this, "There were problems sending activation code!" + e, Toast.LENGTH_LONG).show(); // some other problem
}
Looper.loop();
}
return "";
}
@Override
protected void onProgressUpdate(Integer... progress)
{
super.onProgressUpdate(progress);
}
@Override
protected void onPostExecute(String r)
{
super.onPostExecute(r);
}
}