I have this simple code with another jar library to enable me to send email without going to other mailing apps.
public class claimrewardemail extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.successful);
final String username = "myname@gmail.com";
final String password = "mypassword";
new Thread(new Runnable() {
@Override
public void run() {
try {
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
return new javax.mail.PasswordAuthentication(
username, password);
}
});
// TODO Auto-generated method stub
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("from-email@gmail.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("youremail@gmail.com"));
message.setSubject("email");
message.setText("HI,"
+ "\n\n great");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}).start();
}
}
This code above help me send mail directly with hard-coded email, title, and message,now I want to add attachment part which I can access my file in the phone and add in a button which I can send attachment along with this mail. Anyone can help me?