guileen / node-sendmail

send mail without setting up a SMTP server
http://guileen.github.com/node-sendmail
MIT License
560 stars 108 forks source link

ESERVFAIL queryMx #53

Closed savaryt closed 6 years ago

savaryt commented 6 years ago

Expected Behavior

Should work. PS: I'm also getting the ECONNRESET error as described in #48, while the mail is correctly sent in local mode, reason why I'm filtering this error from error handling.

Current Behavior

Works on local firebase functions. Doesn't work on deployed firebase functions.

Steps to Reproduce (for bugs)

Code on functions

import * as functions from 'firebase-functions';
const sendmail = require('sendmail')();
const cors = require('cors');

export const sendMail = functions.https.onRequest((req, res) => {
  cors({ origin: true })(req, res, () => {
    const data = req.body;
    sendmail({
      from: data.email,
      to: 'somemail@protonmail.ch',
      subject: data.subject,
      html: data.content,
    }, (error, reply) => {
      if (error && error.code !== 'ECONNRESET') {
        console.error(error);
      } else {
        res.send({ message: 'success' });
      }
    });
  });

});

Code on Angular client

  onSubmit() {
    const { email, subject, reference, content } = this.form.value;
    // Crashes on functions hosting for some reason while working on local serving
   this.http.post(`${environment.functions.root}sendMail`, { email, subject, reference, content })
      .pipe(first())
      .subscribe(
        ({ message }: { message }) => {
          if (message === 'success') {
            this.feedback.message.next(new FeedbackMessage('Message sent'));
          }
        },
        (error) => {
          this.feedback.message.next(new FeedbackMessage('Message couldn\'t be sent'));
          console.error('error');
        }
      );

Error on firebase function console

error on connectMx Error: queryMx ESERVFAIL protonmail.ch
    at errnoException (dns.js:28:10)
    at QueryReqWrap.onresolve [as oncomplete] (dns.js:219:19)
{ Error: queryMx ESERVFAIL protonmail.ch
    at errnoException (dns.js:28:10)
    at QueryReqWrap.onresolve [as oncomplete] (dns.js:219:19)
  code: 'ESERVFAIL',
  errno: 'ESERVFAIL',
  syscall: 'queryMx',
  hostname: 'protonmail.ch' }

Context

Your Environment

Node 6.11.5 Angular 6.1 package.json

{
    "cors": "^2.8.4",
    "firebase-admin": "^5.13.1",
    "firebase-functions": "^2.0.2",
    "sendmail": "^1.4.1"
}
savaryt commented 6 years ago

External network isnt available on free firebase functions accounts.