protected Boolean doInBackground(List<MailMessage>... anexos) {
    try {
      List<MailMessage> mails = anexos[0];

      boolean parts = mails.size() > 1;
      int i = 1;
      int total = mails.size();

      boolean media = Utils.getConfiguracao(gmail.getContext()).isMedia();

      for (MailMessage mail : mails) {

        String subject = assunto;
        String log = "log.zip";

        if (parts || media) {
          if (total > 1) {
            subject += " - " + i + "/" + total;
            log = String.format("log %d/%d.zip", i, total);
            i++;
          }
          gmail.addAttachment(log, mail.getZip());
        } else {

          Set<String> keys = mail.getAnexos().keySet();

          for (String key : keys) {

            byte[] anexo = mail.getAnexos().get(key);
            if (anexo != null) {
              gmail.addAttachment(key, anexo);
            }
          }
        }

        gmail.sendMail(subject, "Check the attached file", null, destinatario);
        Thread.sleep(10000);

        gmail.clearAttachments();
      }

      return true;
    } catch (AuthenticationFailedException e) {
      Log.e(SendEmailAsyncTask.class.getName(), "Bad account details");
      e.printStackTrace();
      return false;
    } catch (MessagingException e) {
      e.printStackTrace();
      return false;
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
  }
Пример #2
0
  public void sendEmail() throws MessagingException {
    try {
      Transport transport = mailSession.getTransport("smtp");
      transport.connect(emailHost, fromEmail, fromPassword);

      transport.sendMessage(emailMessage, emailMessage.getAllRecipients());
      transport.close();

    } catch (AuthenticationFailedException afe) {
      afe.printStackTrace();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Пример #3
0
  /**
   * Funkcija koja se poziva pritiskom na određeni gumb i preusmjerava na temelju povratne
   * vrijednosti na željenu stranicu. Provjerava da li su uneseni podaci u log in-u ispravni.
   *
   * @return
   */
  public Boolean citajPoruke() {
    Session session = null;
    Store store = null;
    Folder folder = null;

    session = Session.getDefaultInstance(System.getProperties(), null);
    try {

      store = session.getStore("imap");
      store.connect(this.getEmailPosluzitelj(), this.getEmailKorisnik(), this.getEmailLozinka());
      uspjesnostAutentifikacije = true;
      return uspjesnostAutentifikacije;

    } catch (AuthenticationFailedException e) {
      uspjesnostAutentifikacije = false;
      e.printStackTrace();
      return uspjesnostAutentifikacije;
    } catch (FolderClosedException e) {
      uspjesnostAutentifikacije = false;
      e.printStackTrace();
      return uspjesnostAutentifikacije;
    } catch (FolderNotFoundException e) {
      uspjesnostAutentifikacije = false;
      e.printStackTrace();
      return uspjesnostAutentifikacije;
    } catch (NoSuchProviderException e) {
      uspjesnostAutentifikacije = false;
      e.printStackTrace();
      return uspjesnostAutentifikacije;
    } catch (ReadOnlyFolderException e) {
      uspjesnostAutentifikacije = false;
      e.printStackTrace();
      return uspjesnostAutentifikacije;
    } catch (StoreClosedException e) {
      uspjesnostAutentifikacije = false;
      e.printStackTrace();
      return uspjesnostAutentifikacije;
    } catch (Exception e) {
      uspjesnostAutentifikacije = false;
      e.printStackTrace();
      return uspjesnostAutentifikacije;
    }
  }
 private void sendEmail() {
   if (day.split(",")[getcDay() - 1].equals("true") || date) {
     GmailSender sender = new GmailSender(username, pass);
     try {
       sender.sendMail(subject, message, username, recipient);
       logSend("Email", getFormattedTime(), message, recipient, true);
     } catch (AddressException e) {
       e.printStackTrace();
       sendError = true;
     } catch (AuthenticationFailedException e) {
       e.printStackTrace();
       sendError = true;
     } catch (MessagingException e) {
       e.printStackTrace();
       sendError = true;
     }
     if (!sendError) {
       if (prefs.getBoolean("notify", true)) {
         if (!prefs.getBoolean("notifyIntrusive", true)) {
           mHandler.post(
               new Runnable() {
                 @Override
                 public void run() {
                   Toast.makeText(ctx, message, Toast.LENGTH_LONG).show();
                 }
               });
         } else {
           alertE(message, ctx);
         }
       }
     } else {
       logSend("Email", getFormattedTime(), message, recipient, false);
       mHandler.post(
           new Runnable() {
             @Override
             public void run() {
               Toast.makeText(ctx, "Error while sending, " + message, Toast.LENGTH_LONG).show();
             }
           });
     }
   }
 }