M
M
mbhusty2014-06-03 15:12:38
Java
mbhusty, 2014-06-03 15:12:38

How to organize the sending of results by email?

There is a class in which testing takes place, and at the end of it, an alert window with the results is displayed.
All data is stored in a variable How to organize the transfer of the value of the variable to the body of the letter and send it to the specified mail? If possible, disable text editing.
String stat="";

private void Stats() {
/*		// TODO Auto-generated method stub
    double rating=Math.round(((double)right/((double)right+(double)wrong))*100);
    String stat="";
    stat+=getString(R.string.note1);
    stat+=" "+right+" ";
    stat+=getString(R.string.note2);
    stat+=" "+total_time+". ";
    stat+=getString(R.string.note3);
    stat+=" "+(rating+"").substring(0,(rating+"").length()-2);
    Toast.makeText(this, stat, Toast.LENGTH_LONG).show();*/
    AlertDialog.Builder builder = new AlertDialog.Builder(Test.this);
    double rating=Math.round(((double)right/((double)right+(double)wrong))*100);
    String stat="";
    stat+=getString(R.string.note1);
    stat+=" "+right+" ";
    stat+=getString(R.string.note2);
    stat+=" "+total_time+".\n";
    stat+=getString(R.string.note3);
    stat+=" "+(rating+"").substring(0,(rating+"").length()-2);
    builder.setTitle("Результаты тестирования")
        .setMessage(stat+"\nA – 85-100\nB – 74-85\nС – 61-73\nD – от 0 до 61 (Тест не пройден)")
        .setIcon(R.drawable.result)
        .setCancelable(false)
        .setNegativeButton("Отрпавить результаты по E-mail",

          new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int id) {
                Intent email1 = new Intent(Intent.ACTION_SEND);
                    //Кому
                    email1.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
                    
                        email1.setType("message/rfc822");
                        //О чем
                        email1.putExtra(Intent.EXTRA_SUBJECT, "Результаты тестирования");
                        //Что
                        email1.putExtra(android.content.Intent.EXTRA_TEXT, "Введите пожалуйста Ваше ФИО и результаты тестирования");
                        //Как
                        startActivity(Intent.createChooser(email1, "Выберите email клиент :"));
                
                /*dialog.cancel();*/
              }
            });
    AlertDialog alert = builder.create();
    alert.show();
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
a_f0x, 2014-06-05
@a_f0x

I used the javax.mail library.
here is an example of sending to a mailing list
private void sendMessage2Mail(ArrayList mailList, String mailMessage) {
try{
Properties props = System.getProperties();
props.setProperty("mail.smtp.host", serverMail);//Set connection properties, specify our mail server
props.setProperty("mail.password", passwordMail);
Session session = Session.getInstance(props, null);//Set the session with the given properties
Message msg = new MimeMessage(session);//New message in this session
msg.setFrom(new InternetAddress(loginMail + "@" + serverMail) );//from whom to send
for (String mailAcc : mailList){
Thread.sleep(500);
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(mailAcc, false));
msg.setSubject("Notification Service");//Subject of the message
msg.setSentDate(new Date());//Date of sending
msg.setText(mailMessage);//Text of the message
Transport.send(msg);//send the message !
}
}
catch (MessagingException e) {
e.printStackTrace();
}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question