@Override protected String doInBackground(String... params) { Mail m = new Mail(Secrets.senderEmail, Secrets.senderPassword); String address = (params[0].equals("")) ? "*****@*****.**" : params[0]; String[] toArr = {address}; m.setTo(toArr); m.setFrom(Secrets.senderEmail); m.setSubject("Network Traffic Log"); m.setBody("Email body."); String[] attachments = {"log1.txt", "error.txt", "fail.txt"}; try { for (String attachment : attachments) { String path = "/data/local/Warden/" + attachment; if (fileExists(path)) { m.addAttachment(path); } else { Log.e("Network Warden", "Attachment file doesn't exist: " + path); } } m.send(); } catch (MessagingException e) { Log.e("Network Warden", "Could not send email", e); return "Could not send email"; } return "Email sent!"; }