Отправить вложение через Nodemailer из приложения Android - PullRequest
0 голосов
/ 06 декабря 2018

Мне нужно отправить вложение из моего приложения для Android.Я использую Nodemailer и Cloud Functions для отправки электронных писем клиентам, и это работает, но если я попытался отправить вложение, в моем случае какой-нибудь html-файл, я получил ошибку в Firebase Console:

Unhandled error { Error: ENOENT: no such file or directory, open 'file:///storage/emulated/0/Invoice/Receipt.html'
at Error (native)
errno: -2,
code: 'ESTREAM',
syscall: 'open',
path: 'file:///storage/emulated/0/Invoice/Receipt.html',
command: 'API' } 

Но дело в том,если я пытаюсь отправить то же вложение, используя Intent, например: файл emailIntent.putExtra(Intent.EXTRA_STREAM, path); есть, и я могу отправить его, и я это сделал, так что, по крайней мере, моя проблема не связана с путем.

Вот код Java, где я создаю вложение для отправки:

try {
        Uri fromFile = Uri.fromFile(file);

        JSONArray array = new JSONArray();
        JSONObject object = new JSONObject();
        object.put("filename", "Receipt.html");
        object.put("path", fromFile);
        object.put("contentType", "text/html");
        array.put(object);

        HashMap<String, Object> data = new HashMap<>();
        data.put("email", customer.getEmail());
        data.put("attachment", array);
        data.put("info", getStoreInformations());
        data.put("subject", "Receipt");
        data.put("push", true);

        return functions
                .getHttpsCallable("sendTestingEmail")
                .call(data)
                .continueWith(new Continuation<HttpsCallableResult, String>() {
                    @Override
                    public String then(@NonNull Task<HttpsCallableResult> task) throws Exception {
                        // This continuation runs on either success or failure, but if the task
                        // has failed then getResult() will throw an Exception which will be
                        // propagated down.
                        String result = (String) task.getResult().getData();
                        Log.d("Result", result);
                        Toast.makeText(context, "Email sent", Toast.LENGTH_SHORT).show();
                        return result;
                    }
                });
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

А вот function из Nod.js:

function sendTestingEmail(email, attachment, info, subject){

const mailOptions = {
  from: '******@gmail.com',
  to: email,
  attachments: attachment,
  text: info,
  subject: subject
};

return mailTransport.sendMail(mailOptions).then(() => {
  return console.log('Test email sent: ', email);
  });
}

Кто-нибудьзнаете, что я делаю неправильно и как я могу отправлять файлы из приложения Android по электронной почте с помощью Nodemailer, Cloud Functions и Node.js?

...