I'm trying to send an email from my Android app directly to the recipient. But when I click send nothing happens. The success toast doesn't appear.
I used these classes: JSSEProvider, ByteArrayDatasource,MailSender
This is my main code:
Send_mail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if ("".equals(recipient_mail.getText().toString().trim())) {
Toast.makeText(FirstActivity.this, "Enter Recipent Email ", Toast.LENGTH_SHORT).show();
} else {
new Thread(new Runnable() {
@Override
public void run() {
try {
MailSender sender = new MailSender(sender_mail.getText().toString(),
mail_password.getText().toString());
sender.sendMail(Subject.getText().toString(), Text.getText().toString(),
sender_mail.getText().toString(), recipient_mail.getText().toString());
Toast.makeText(context, "Success!", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Log.e("SendMail", e.getMessage(), e);
}
}
}).start();
}
}
});
This is my dialog activity:
You can not show a Toast message within a thread, you need to reach the main thread to achieve this. So, replace your toast message with this
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(FirstActivity.this, "Success!", Toast.LENGTH_SHORT).show();
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.