Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto","correo@gmail.com", null));
- emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Android APP - ");
- startActivity(Intent.createChooser(emailIntent, getActivity().getString(R.string.enviar_mail)));
- String[] TO = {""}; //Direcciones email a enviar.
- String[] CC = {""}; //Direcciones email con copia.
- Intent emailIntent = new Intent(Intent.ACTION_SEND);
- emailIntent.setData(Uri.parse("mailto:"));
- emailIntent.setType("text/plain");
- emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
- emailIntent.putExtra(Intent.EXTRA_CC, CC);
- emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Tu Asunto...");
- emailIntent.putExtra(Intent.EXTRA_TEXT, "tuemail@email.com"); // * configurar email aquí!
- try {
- startActivity(Intent.createChooser(emailIntent, "Enviar email."));
- Log.i("EMAIL", "Enviando email...");
- }
- catch (android.content.ActivityNotFoundException e) {
- Toast.makeText(this, "NO existe ningún cliente de email instalado!.", Toast.LENGTH_SHORT).show();
- }
- repositories {
- jcenter()
- maven {
- url "https://maven.java.net/content/groups/public/"
- }
- }
- dependencies {
- compile 'com.sun.mail:android-mail:1.5.5'
- compile 'com.sun.mail:android-activation:1.5.5'
- }
- /**
- * Created by snolde on 06-04-2017.
- */
- public class MailJob extends AsyncTask<MailJob.Mail,Void,Void>{
- private final String user;
- private final String pass;
- public MailJob(String user, String pass) {
- super();
- this.user=user;
- this.pass=pass;
- }
- @Override
- protected Void doInBackground(Mail... mails) {
- 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 PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(user, pass);
- }
- });
- for (Mail mail:mails) {
- try {
- Message message = new MimeMessage(session);
- message.setFrom(new InternetAddress(mail.from));
- message.setRecipients(Message.RecipientType.TO,
- InternetAddress.parse(mail.to));
- message.setSubject(mail.subject);
- message.setText(mail.content);
- Transport.send(message);
- } catch (MessagingException e) {
- Log.d("MailJob", e.getMessage());
- }
- }
- return null;
- }
- public static class Mail{
- private final String subject;
- private final String content;
- private final String from;
- private final String to;
- public Mail(String from, String to, String subject, String content){
- this.subject=subject;
- this.content=content;
- this.from=from;
- this.to=to;
- }
- }
- }
- new MailJob(user, passwd).execute(
- new MailJob.Mail("from@gmail.com", "to@otromail.com", "subjeto", "contenido")
- );
Add Comment
Please, Sign In to add comment