android: Sending Emails without User Intervention...Time interval? Service
unavailable?
I am working on sending an activation code to the user's email account
using the below code (following from the site Sending Emails without User
Intervention (no Intents) in Android
http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_(no_Intents)_in_Android)
Question:
Everything is working perfectly for the first time pressing the activation
button, and the activation code is well received in the designated email.
However, when I press the activation button starting from the second time,
it will just toast out the message "Generating activation code" but
without the "Activation code sent successfully!\nPlease check email after
5 minutes" and thereby no email is received at all.
I would like to ask
Is there any minimum time interval for such service (smtp.gmail.com) to be
performed? I have pressed again after 5 minutes and the email still cannot
be sent. If not, how could the codes be modified?
Is it possible for emails other than gmail? The email would be send and
receive using the same email.
If my app is published using this service, in that case, many users may
request activation code at the same time, would the service be
unavailable?
Thanks in advance!!
Coding as follows:
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);
}
}
No comments:
Post a Comment