Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to send a mail in production but in developement everything is fine #1156

Closed
dbonattoj opened this issue Jun 26, 2020 · 6 comments
Closed
Labels
status: waiting for feedback waiting for feedback from the submitter type: question question directed at the library

Comments

@dbonattoj
Copy link

Issue Summary

In localhost I can send mails without any issues, while when the website is pushed into production, I receive a ECONNRESET error..

Code Snippet

const sgMail = require("@sendgrid/mail")
sgMail.setApiKey('REMOVED');

const msg = {
        to: ['REMOVED', mail],
        from: 'REMOVED',
        subject: 'RVS - ' + subj + ' - ' + name,
        text: String(text),
        html: String(text),
    };

    sgMail.send(msg).then(() => {
        console.log('Message sent', msg)
    }).catch((error) => {
        console.log(error)
        console.log(msg)
    })
    response.status(200).json({
        status: 'Mail sent.',
        data: ":)",
    })

Exception/Log


fsserver_1  | Error: read ECONNRESET
fsserver_1  |     at TLSWrap.onStreamRead (internal/stream_base_commons.js:205:27) {
fsserver_1  |   errno: 'ECONNRESET',
fsserver_1  |   code: 'ECONNRESET',
fsserver_1  |   syscall: 'read',
fsserver_1  |   config: {
fsserver_1  |     url: '/v3/mail/send',
fsserver_1  |     method: 'post',
fsserver_1  |     data: '{"from":{"email":"REMOVED"},"subject":"RVS - 2 - B","personalizations":[{"to":[{"email":"REMOVED"},{"email":"REMOVED"}]}],"content":[{"value":"TEST MAIL FROM EXPERIMENT SERVER","type":"text/plain"},{"value":"TEST MAIL FROM EXPERIMENT SERVER","type":"text/html"}]}',
fsserver_1  |     headers: {
fsserver_1  |       Accept: 'application/json',
fsserver_1  |       'Content-Type': 'application/json',
fsserver_1  |       'User-Agent': 'sendgrid/7.1.1;nodejs',
fsserver_1  |       Authorization: 'Bearer REMOVED',
fsserver_1  |       'Content-Length': 305
fsserver_1  |     },
fsserver_1  |     baseURL: 'https://api.sendgrid.com/',
fsserver_1  |     transformRequest: [ [Function: transformRequest] ],
fsserver_1  |     transformResponse: [ [Function: transformResponse] ],
fsserver_1  |     timeout: 0,
fsserver_1  |     adapter: [Function: httpAdapter],
fsserver_1  |     xsrfCookieName: 'XSRF-TOKEN',
fsserver_1  |     xsrfHeaderName: 'X-XSRF-TOKEN',
fsserver_1  |     maxContentLength: Infinity,
fsserver_1  |     validateStatus: [Function: validateStatus]
fsserver_1  |   },
fsserver_1  |   request: Writable {
fsserver_1  |     _writableState: WritableState {
fsserver_1  |       objectMode: false,
fsserver_1  |       highWaterMark: 16384,
fsserver_1  |       finalCalled: false,
fsserver_1  |       needDrain: false,
fsserver_1  |       ending: false,
fsserver_1  |       ended: false,
fsserver_1  |       finished: false,
fsserver_1  |       destroyed: false,
fsserver_1  |       decodeStrings: true,
fsserver_1  |       defaultEncoding: 'utf8',
fsserver_1  |       length: 0,
fsserver_1  |       writing: false,
fsserver_1  |       corked: 0,
fsserver_1  |       sync: true,
fsserver_1  |       bufferProcessing: false,
fsserver_1  |       onwrite: [Function: bound onwrite],
fsserver_1  |       writecb: null,
fsserver_1  |       writelen: 0,
fsserver_1  |       afterWriteTickInfo: null,
fsserver_1  |       bufferedRequest: null,
fsserver_1  |       lastBufferedRequest: null,
fsserver_1  |       pendingcb: 0,
fsserver_1  |       prefinished: false,
fsserver_1  |       errorEmitted: false,
fsserver_1  |       emitClose: true,
fsserver_1  |       autoDestroy: false,
fsserver_1  |       bufferedRequestCount: 0,
fsserver_1  |       corkedRequestsFree: [Object]
fsserver_1  |     },
fsserver_1  |     writable: true,
fsserver_1  |     _events: [Object: null prototype] {
fsserver_1  |       response: [Function: handleResponse],
fsserver_1  |       error: [Function: handleRequestError]
fsserver_1  |     },
fsserver_1  |     _eventsCount: 2,
fsserver_1  |     _maxListeners: undefined,
fsserver_1  |     _options: {
fsserver_1  |       protocol: 'https:',
fsserver_1  |       maxRedirects: 21,
fsserver_1  |       maxBodyLength: Infinity,
fsserver_1  |       path: '/v3/mail/send',
fsserver_1  |       method: 'POST',
fsserver_1  |       headers: [Object],
fsserver_1  |       agent: undefined,
fsserver_1  |       agents: [Object],
fsserver_1  |       auth: undefined,
fsserver_1  |       hostname: 'api.sendgrid.com',
fsserver_1  |       port: null,
fsserver_1  |       nativeProtocols: [Object],
fsserver_1  |       pathname: '/v3/mail/send'
fsserver_1  |     },
fsserver_1  |     _redirectCount: 0,
fsserver_1  |     _redirects: [],
fsserver_1  |     _requestBodyLength: 305,
fsserver_1  |     _requestBodyBuffers: [ [Object] ],
fsserver_1  |     _onNativeResponse: [Function],
fsserver_1  |     _currentRequest: ClientRequest {
fsserver_1  |       _events: [Object: null prototype],
fsserver_1  |       _eventsCount: 6,
fsserver_1  |       _maxListeners: undefined,
fsserver_1  |       outputData: [],
fsserver_1  |       outputSize: 0,
fsserver_1  |       writable: true,
fsserver_1  |       _last: true,
fsserver_1  |       chunkedEncoding: false,
fsserver_1  |       shouldKeepAlive: false,
fsserver_1  |       useChunkedEncodingByDefault: true,
fsserver_1  |       sendDate: false,
fsserver_1  |       _removedConnection: false,
fsserver_1  |       _removedContLen: false,
fsserver_1  |       _removedTE: false,
fsserver_1  |       _contentLength: null,
fsserver_1  |       _hasBody: true,
fsserver_1  |       _trailer: '',
fsserver_1  |       finished: false,
fsserver_1  |       _headerSent: true,
fsserver_1  |       socket: [TLSSocket],
fsserver_1  |       connection: [TLSSocket],
fsserver_1  |       _header: 'POST /v3/mail/send HTTP/1.1\r\n' +
fsserver_1  |         'Accept: application/json\r\n' +
fsserver_1  |         'Content-Type: application/json\r\n' +
fsserver_1  |         'User-Agent: sendgrid/7.1.1;nodejs\r\n' +
fsserver_1  |         'Authorization: Bearer REMOVED\r\n' +
fsserver_1  |         'Content-Length: 305\r\n' +
fsserver_1  |         'Host: api.sendgrid.com\r\n' +
fsserver_1  |         'Connection: close\r\n' +
fsserver_1  |         '\r\n',
fsserver_1  |       _onPendingData: [Function: noopPendingOutput],
fsserver_1  |       agent: [Agent],
fsserver_1  |       socketPath: undefined,
fsserver_1  |       method: 'POST',
fsserver_1  |       insecureHTTPParser: undefined,
fsserver_1  |       path: '/v3/mail/send',
fsserver_1  |       _ended: false,
fsserver_1  |       res: null,
fsserver_1  |       aborted: false,
fsserver_1  |       timeoutCb: null,
fsserver_1  |       upgradeOrConnect: false,
fsserver_1  |       parser: null,
fsserver_1  |       maxHeadersCount: null,
fsserver_1  |       reusedSocket: false,
fsserver_1  |       _redirectable: [Circular],
fsserver_1  |       [Symbol(kCapture)]: false,
fsserver_1  |       [Symbol(kNeedDrain)]: false,
fsserver_1  |       [Symbol(corked)]: 0,
fsserver_1  |       [Symbol(kOutHeaders)]: [Object: null prototype]
fsserver_1  |     },
fsserver_1  |     _currentUrl: 'https://api.sendgrid.com/v3/mail/send',
fsserver_1  |     [Symbol(kCapture)]: false
fsserver_1  |   },
fsserver_1  |   response: undefined,
fsserver_1  |   isAxiosError: true,
fsserver_1  |   toJSON: [Function]
fsserver_1  | }
fsserver_1  | {
fsserver_1  |   to: [ 'REMOVED' ],
fsserver_1  |   from: 'REMOVED',
fsserver_1  |   subject: 'RVS - 2 - B',
fsserver_1  |   text: 'TEST MAIL FROM EXPERIMENT SERVER',
fsserver_1  |   html: 'TEST MAIL FROM EXPERIMENT SERVER',
fsserver_1  |   isMultiple: false,
fsserver_1  |   substitutionWrappers: [ '{{', '}}' ]
fsserver_1  | }

Technical details:

  • sendgrid-nodejs version: 7.1.1
  • node version: 0.0.0

I think it is a proxy problem, but I don't know how to solve it, I only found some information in java and they don't seems to work here sendgrid/sendgrid-java#182

Thanks

@thinkingserious
Copy link
Contributor

Hello @dbonattoj,

This does not appear to be an issue with the helper library.

I think your initial thought of the error being caused by a proxy issue with your production server may be correct. Can you please confirm with the server admin? This StackOverflow question might help withe debugging also.

With best regards,

Elmer

@thinkingserious thinkingserious added status: waiting for feedback waiting for feedback from the submitter type: question question directed at the library labels Jun 26, 2020
@dbonattoj
Copy link
Author

dbonattoj commented Jun 27, 2020

From the log, it seems that it is doing a POST request to https://api.sendgrid.com/.

I'm also doing POST request to other services without issues, I'm not so sure it is the real problem here.

At least a more meaningful help message would be interesting, because ECONNRESET can say anything in this context.

From the source code (https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/client/src/classes/client.js) I see that you are using Axios to make the POST requests, However, my others Axios requests work properly, I will dig in that direction anyway.

The server at the moment is not using https, could that be an issue?

@thinkingserious
Copy link
Contributor

thinkingserious commented Jul 2, 2020

Can you please try making a hello world API call via cURL from your server?

The server at the moment is not using https, could that be an issue?

I think so, trying the cURL command above may help us further pinpoint where the issue resides.

@dbonattoj
Copy link
Author

I receive a

curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to api.sendgrid.com:443

After a netstat -lntu
The port 443 is effectively closed, I will ask to open it and hope it was the issue.

Do I need to open it in/out? We have very strict policies on open ports

Are some other usual ports needed for using Sendgrid?

@dbonattoj
Copy link
Author

Apparently, even with the 443 open,
the domain https://api.sendgrid.com is blocked at a higher level.. on a firewall over my firewall,
From outside this link gives me "404 not found" while from work it gives an empty page with "connection_reset"

I guess I will need to use another service or find out how to send smtp mails in javascript.

@thinkingserious
Copy link
Contributor

I suggest that you (or the admin of your server) reach out to our support team with a link to this GitHub issue for further assistance. The issue appears to be network related vs. helper library related, so I will close the issue here. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for feedback waiting for feedback from the submitter type: question question directed at the library
Projects
None yet
Development

No branches or pull requests

2 participants