Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to send the email using Android Code [closed]
- Intent i = new Intent(Intent.ACTION_SEND);
- i.setType("text/plain");
- i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient@example.com"});
- i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
- i.putExtra(Intent.EXTRA_TEXT , "body of email");
- try {
- startActivity(Intent.createChooser(i, "Send mail..."));
- } catch (android.content.ActivityNotFoundException ex) {
- Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
- }
- Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
- String[] recipients = new String[]{"my@email.com", "",};
- emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
- emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test");
- emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is email's message");
- emailIntent.setType("text/plain");
- startActivity(Intent.createChooser(emailIntent, "Send mail..."));
- String to = "abcd@gmail.com";
- String from = "web@gmail.com";
- Properties properties = System.getProperties();
- properties.setProperty("mail.smtp.host", SMPT_HOSTNAME);
- Session session = Session.getInstance(properties, new Authenticator() {
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(USERNAME, PASSWORD);
- }
- });
- try {
- MimeMessage message = new MimeMessage(session);
- message.setFrom(new InternetAddress(from));
- message.addRecipient(Message.RecipientType.TO, new InternetAddress(
- to));
- message.setSubject("This is the Subject Line!");
- message.setText("This is actual message");
- Transport.send(message);
- System.out.println("Sent message successfully....");
- } catch (MessagingException mex) {
- mex.printStackTrace();
- }
Add Comment
Please, Sign In to add comment