Wednesday, November 23, 2011

How to send Email in Android ?

Mail m = new Mail("USER EMAIL", "PASSWORD"); 
String[] toArr = {"EMAIL-1", "EMAIL-2"}; 
m.setTo(toArr); 
m.setFrom("USER EMAIL"); 
m.setSubject("This is an email sent using my Mail JavaMail wrapper from an Android device."); 
m.setBody("Email body"); 
try { 
  m.addAttachment("/sdcard/bday.jpg"); 
  if(m.send()) { 
    Toast.makeText(this, "Email was sent successfully.", Toast.LENGTH_LONG).show(); 
  } else { 
    Toast.makeText(this, "Email was not sent.", Toast.LENGTH_LONG).show(); 
  } 
} catch(Exception e) { 
  Log.e("MailApp", "Could not send email", e); 
} 

No comments:

Post a Comment