I want mail sent in background with file attach from mobile memory in background without intent or user interaction.
Please help me.
I want mail sent in background with file attach from mobile memory in background without intent or user interaction.
Please help me.
You can do this with JavaMail API and Java Activation Framework (JAF) here is
Download javamal api jar files, and do like this
recpient= reciept.getText().toString();
subject= sub.getText().toString();
textmessage= msg.getText().toString();
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("Your Gmail-ID", "Your Gmail_password");
}
});
pdialog = ProgressDialog.show(context, "", "Sending Mail...",true);
RetreiveFeedTask task= new RetreiveFeedTask();
task.execute();
}
class RetreiveFeedTask extends AsyncTask<string string="" void=""> {
protected String doInBackground(String... urls) {
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("</string><string string="" void="">Your Gmail-ID"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recpient));
message.setSubject(subject);
message.setContent(textmessage, "text/html; charset=utf-8");
Transport.send(message);
}
catch (MessagingException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String feed) {
pdialog.dismiss();
reciept.setText("");
msg.setText("");
sub.setText("");
Toast.makeText(getApplicationContext(), "Message sent", Toast.LENGTH_LONG).show();
}
}
}