Uploaded image for project: 'TrueNAS'
  1. TrueNAS
  2. NAS-108932

Sending email always causes a broken pipe error

    XMLWordPrintable

    Details

      Description

      I'd like to send email via GMail to my own GMail address. I have "broken pipe" errors both when using GMail OAuth and when using SMTP with an app password. This is TrueNAS-12.0-U1.

       

      First the OAuth case. Sending test emails works at first, but if I let the system wait for a while, they won't work. Alerts won't work either.

       

      Here's what I got in middlewared.log:

      [2021/01/07 00:00:08] (DEBUG) google_auth_httplib2.__call__():114 - Making request: POST https://oauth2.googleapis.com/token
      [2021/01/07 00:00:08] (WARNING) MailService.send_raw():420 - Failed to send email: [Errno 32] Broken pipe
      Traceback (most recent call last):
        File "/usr/local/lib/python3.8/site-packages/middlewared/plugins/mail.py", line 393, in send_raw
          self.middleware.call_sync('mail.gmail_send', msg, config)
        File "/usr/local/lib/python3.8/site-packages/middlewared/main.py", line 1265, in call_sync
          return methodobj(*prepared_call.args)
        File "/usr/local/lib/python3.8/site-packages/middlewared/plugins/mail_/gmail.py", line 63, in gmail_send
          gmail_service.service.users().messages().send(userId="me", body={
        File "/usr/local/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
          return wrapped(*args, **kwargs)
        File "/usr/local/lib/python3.8/site-packages/googleapiclient/http.py", line 900, in execute
          resp, content = _retry_request(
        File "/usr/local/lib/python3.8/site-packages/googleapiclient/http.py", line 204, in _retry_request
          raise exception
        File "/usr/local/lib/python3.8/site-packages/googleapiclient/http.py", line 177, in _retry_request
          resp, content = http.request(uri, method, *args, **kwargs)
        File "/usr/local/lib/python3.8/site-packages/google_auth_httplib2.py", line 186, in request
          self.credentials.before_request(
        File "/usr/local/lib/python3.8/site-packages/google/auth/credentials.py", line 133, in before_request
          self.refresh(request)
        File "/usr/local/lib/python3.8/site-packages/google/oauth2/credentials.py", line 200, in refresh
          access_token, refresh_token, expiry, grant_response = _client.refresh_grant(
        File "/usr/local/lib/python3.8/site-packages/google/oauth2/_client.py", line 248, in refresh_grant
          response_data = _token_endpoint_request(request, token_uri, body)
        File "/usr/local/lib/python3.8/site-packages/google/oauth2/_client.py", line 105, in _token_endpoint_request
          response = request(method="POST", url=token_uri, headers=headers, body=body)
        File "/usr/local/lib/python3.8/site-packages/google_auth_httplib2.py", line 115, in __call__
          response, data = self.http.request(
        File "/usr/local/lib/python3.8/site-packages/httplib2/__init__.py", line 1982, in request
          (response, content) = self._request(
        File "/usr/local/lib/python3.8/site-packages/httplib2/__init__.py", line 1650, in _request
          (response, content) = self._conn_request(
        File "/usr/local/lib/python3.8/site-packages/httplib2/__init__.py", line 1558, in _conn_request
          conn.request(method, request_uri, body, headers)
        File "/usr/local/lib/python3.8/http/client.py", line 1255, in request
          self._send_request(method, url, body, headers, encode_chunked)
        File "/usr/local/lib/python3.8/http/client.py", line 1301, in _send_request
          self.endheaders(body, encode_chunked=encode_chunked)
        File "/usr/local/lib/python3.8/http/client.py", line 1250, in endheaders
          self._send_output(message_body, encode_chunked=encode_chunked)
        File "/usr/local/lib/python3.8/http/client.py", line 1010, in _send_output
          self.send(msg)
        File "/usr/local/lib/python3.8/http/client.py", line 971, in send
          self.sock.sendall(data)
        File "/usr/local/lib/python3.8/ssl.py", line 1204, in sendall
          v = self.send(byte_view[count:])
        File "/usr/local/lib/python3.8/ssl.py", line 1173, in send
          return self._sslobj.write(data)
      BrokenPipeError: [Errno 32] Broken pipe
      [2021/01/07 00:00:08] (ERROR) middlewared.job.run():373 - Job <bound method accepts.<locals>.wrap.<locals>.nf of <middlewared.plugins.mail.MailService object at 0x81c4210d0>> failed
      Traceback (most recent call last):
        File "/usr/local/lib/python3.8/site-packages/middlewared/plugins/mail.py", line 393, in send_raw
          self.middleware.call_sync('mail.gmail_send', msg, config)
        File "/usr/local/lib/python3.8/site-packages/middlewared/main.py", line 1265, in call_sync
          return methodobj(*prepared_call.args)
        File "/usr/local/lib/python3.8/site-packages/middlewared/plugins/mail_/gmail.py", line 63, in gmail_send
          gmail_service.service.users().messages().send(userId="me", body={
        File "/usr/local/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
          return wrapped(*args, **kwargs)
        File "/usr/local/lib/python3.8/site-packages/googleapiclient/http.py", line 900, in execute
          resp, content = _retry_request(
        File "/usr/local/lib/python3.8/site-packages/googleapiclient/http.py", line 204, in _retry_request
          raise exception
        File "/usr/local/lib/python3.8/site-packages/googleapiclient/http.py", line 177, in _retry_request
          resp, content = http.request(uri, method, *args, **kwargs)
        File "/usr/local/lib/python3.8/site-packages/google_auth_httplib2.py", line 186, in request
          self.credentials.before_request(
        File "/usr/local/lib/python3.8/site-packages/google/auth/credentials.py", line 133, in before_request
          self.refresh(request)
        File "/usr/local/lib/python3.8/site-packages/google/oauth2/credentials.py", line 200, in refresh
          access_token, refresh_token, expiry, grant_response = _client.refresh_grant(
        File "/usr/local/lib/python3.8/site-packages/google/oauth2/_client.py", line 248, in refresh_grant
          response_data = _token_endpoint_request(request, token_uri, body)
        File "/usr/local/lib/python3.8/site-packages/google/oauth2/_client.py", line 105, in _token_endpoint_request
          response = request(method="POST", url=token_uri, headers=headers, body=body)
        File "/usr/local/lib/python3.8/site-packages/google_auth_httplib2.py", line 115, in __call__
          response, data = self.http.request(
        File "/usr/local/lib/python3.8/site-packages/httplib2/__init__.py", line 1982, in request
          (response, content) = self._request(
        File "/usr/local/lib/python3.8/site-packages/httplib2/__init__.py", line 1650, in _request
          (response, content) = self._conn_request(
        File "/usr/local/lib/python3.8/site-packages/httplib2/__init__.py", line 1558, in _conn_request
          conn.request(method, request_uri, body, headers)
        File "/usr/local/lib/python3.8/http/client.py", line 1255, in request
          self._send_request(method, url, body, headers, encode_chunked)
        File "/usr/local/lib/python3.8/http/client.py", line 1301, in _send_request
          self.endheaders(body, encode_chunked=encode_chunked)
        File "/usr/local/lib/python3.8/http/client.py", line 1250, in endheaders
          self._send_output(message_body, encode_chunked=encode_chunked)
        File "/usr/local/lib/python3.8/http/client.py", line 1010, in _send_output
          self.send(msg)
        File "/usr/local/lib/python3.8/http/client.py", line 971, in send
          self.sock.sendall(data)
        File "/usr/local/lib/python3.8/ssl.py", line 1204, in sendall
          v = self.send(byte_view[count:])
        File "/usr/local/lib/python3.8/ssl.py", line 1173, in send
          return self._sslobj.write(data)
      BrokenPipeError: [Errno 32] Broken pipe
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "/usr/local/lib/python3.8/site-packages/middlewared/job.py", line 361, in run
          await self.future
        File "/usr/local/lib/python3.8/site-packages/middlewared/job.py", line 399, in __run_body
          rv = await self.middleware.run_in_thread(self.method, *([self] + args))
        File "/usr/local/lib/python3.8/site-packages/middlewared/utils/run_in_thread.py", line 10, in run_in_thread
          return await self.loop.run_in_executor(self.run_in_thread_executor, functools.partial(method, *args, **kwargs))
        File "/usr/local/lib/python3.8/site-packages/middlewared/utils/io_thread_pool_executor.py", line 25, in run
          result = self.fn(*self.args, **self.kwargs)
        File "/usr/local/lib/python3.8/site-packages/middlewared/schema.py", line 977, in nf
          return f(*args, **kwargs)
        File "/usr/local/lib/python3.8/site-packages/middlewared/plugins/mail.py", line 261, in send
          return self.send_raw(job, message, config)
        File "/usr/local/lib/python3.8/site-packages/middlewared/schema.py", line 977, in nf
          return f(*args, **kwargs)
        File "/usr/local/lib/python3.8/site-packages/middlewared/plugins/mail.py", line 424, in send_raw
          raise CallError(f'Failed to send email: {e}')
      middlewared.service_exception.CallError: [EFAULT] Failed to send email: [Errno 32] Broken pipe
      

      I googled a bit and found this https://stackoverflow.com/questions/48019198/brokenpipeerror-when-using-gmail-api  which then led me here https://github.com/googleapis/google-api-python-client/issues/218 

      Maybe it's an unsolved issue in the Google Python API libraries?


      Second, the SMTP case. I saw this when I tried sending a test email after the SMTP stuff had been configured for a few days. The email was sent anyway.

      [2021/01/09 20:30:07] (DEBUG) google_auth_httplib2.__call__():114 - Making request: POST https://oauth2.googleapis.com/token
      [2021/01/09 20:30:07] (WARNING) MailService.send_raw():420 - Failed to send email: [Errno 32] Broken pipe
      Traceback (most recent call last):
        File "/usr/local/lib/python3.8/site-packages/middlewared/plugins/mail.py", line 393, in send_raw
          self.middleware.call_sync('mail.gmail_send', msg, config)
        File "/usr/local/lib/python3.8/site-packages/middlewared/main.py", line 1265, in call_sync
          return methodobj(*prepared_call.args)
        File "/usr/local/lib/python3.8/site-packages/middlewared/plugins/mail_/gmail.py", line 63, in gmail_send
          gmail_service.service.users().messages().send(userId="me", body={
        File "/usr/local/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
          return wrapped(*args, **kwargs)
        File "/usr/local/lib/python3.8/site-packages/googleapiclient/http.py", line 900, in execute
          resp, content = _retry_request(
        File "/usr/local/lib/python3.8/site-packages/googleapiclient/http.py", line 204, in _retry_request
          raise exception
        File "/usr/local/lib/python3.8/site-packages/googleapiclient/http.py", line 177, in _retry_request
          resp, content = http.request(uri, method, *args, **kwargs)
        File "/usr/local/lib/python3.8/site-packages/google_auth_httplib2.py", line 197, in request
          response, content = self.http.request(
        File "/usr/local/lib/python3.8/site-packages/httplib2/__init__.py", line 1982, in request
          (response, content) = self._request(
        File "/usr/local/lib/python3.8/site-packages/httplib2/__init__.py", line 1650, in _request
          (response, content) = self._conn_request(
        File "/usr/local/lib/python3.8/site-packages/httplib2/__init__.py", line 1558, in _conn_request
          conn.request(method, request_uri, body, headers)
        File "/usr/local/lib/python3.8/http/client.py", line 1255, in request
          self._send_request(method, url, body, headers, encode_chunked)
        File "/usr/local/lib/python3.8/http/client.py", line 1301, in _send_request
          self.endheaders(body, encode_chunked=encode_chunked)
        File "/usr/local/lib/python3.8/http/client.py", line 1250, in endheaders
          self._send_output(message_body, encode_chunked=encode_chunked)
        File "/usr/local/lib/python3.8/http/client.py", line 1010, in _send_output
          self.send(msg)
        File "/usr/local/lib/python3.8/http/client.py", line 971, in send
          self.sock.sendall(data)
        File "/usr/local/lib/python3.8/ssl.py", line 1204, in sendall
          v = self.send(byte_view[count:])
        File "/usr/local/lib/python3.8/ssl.py", line 1173, in send
          return self._sslobj.write(data)
      BrokenPipeError: [Errno 32] Broken pipe
      [2021/01/09 20:30:07] (ERROR) middlewared.job.run():373 - Job <bound method accepts.<locals>.wrap.<locals>.nf of <middlewared.plugins.mail.MailService object at 0x81c4210d0>> failed
      Traceback (most recent call last):
        File "/usr/local/lib/python3.8/site-packages/middlewared/plugins/mail.py", line 393, in send_raw
          self.middleware.call_sync('mail.gmail_send', msg, config)
        File "/usr/local/lib/python3.8/site-packages/middlewared/main.py", line 1265, in call_sync
          return methodobj(*prepared_call.args)
        File "/usr/local/lib/python3.8/site-packages/middlewared/plugins/mail_/gmail.py", line 63, in gmail_send
          gmail_service.service.users().messages().send(userId="me", body={
        File "/usr/local/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
          return wrapped(*args, **kwargs)
        File "/usr/local/lib/python3.8/site-packages/googleapiclient/http.py", line 900, in execute
          resp, content = _retry_request(
        File "/usr/local/lib/python3.8/site-packages/googleapiclient/http.py", line 204, in _retry_request
          raise exception
        File "/usr/local/lib/python3.8/site-packages/googleapiclient/http.py", line 177, in _retry_request
          resp, content = http.request(uri, method, *args, **kwargs)
        File "/usr/local/lib/python3.8/site-packages/google_auth_httplib2.py", line 197, in request
          response, content = self.http.request(
        File "/usr/local/lib/python3.8/site-packages/httplib2/__init__.py", line 1982, in request
          (response, content) = self._request(
        File "/usr/local/lib/python3.8/site-packages/httplib2/__init__.py", line 1650, in _request
          (response, content) = self._conn_request(
        File "/usr/local/lib/python3.8/site-packages/httplib2/__init__.py", line 1558, in _conn_request
          conn.request(method, request_uri, body, headers)
        File "/usr/local/lib/python3.8/http/client.py", line 1255, in request
          self._send_request(method, url, body, headers, encode_chunked)
        File "/usr/local/lib/python3.8/http/client.py", line 1301, in _send_request
          self.endheaders(body, encode_chunked=encode_chunked)
        File "/usr/local/lib/python3.8/http/client.py", line 1250, in endheaders
          self._send_output(message_body, encode_chunked=encode_chunked)
        File "/usr/local/lib/python3.8/http/client.py", line 1010, in _send_output
          self.send(msg)
        File "/usr/local/lib/python3.8/http/client.py", line 971, in send
          self.sock.sendall(data)
        File "/usr/local/lib/python3.8/ssl.py", line 1204, in sendall
          v = self.send(byte_view[count:])
        File "/usr/local/lib/python3.8/ssl.py", line 1173, in send
          return self._sslobj.write(data)
      BrokenPipeError: [Errno 32] Broken pipe
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "/usr/local/lib/python3.8/site-packages/middlewared/job.py", line 361, in run
          await self.future
        File "/usr/local/lib/python3.8/site-packages/middlewared/job.py", line 399, in __run_body
          rv = await self.middleware.run_in_thread(self.method, *([self] + args))
        File "/usr/local/lib/python3.8/site-packages/middlewared/utils/run_in_thread.py", line 10, in run_in_thread
          return await self.loop.run_in_executor(self.run_in_thread_executor, functools.partial(method, *args, **kwargs))
        File "/usr/local/lib/python3.8/site-packages/middlewared/utils/io_thread_pool_executor.py", line 25, in run
          result = self.fn(*self.args, **self.kwargs)
        File "/usr/local/lib/python3.8/site-packages/middlewared/schema.py", line 977, in nf
          return f(*args, **kwargs)
        File "/usr/local/lib/python3.8/site-packages/middlewared/plugins/mail.py", line 261, in send
          return self.send_raw(job, message, config)
        File "/usr/local/lib/python3.8/site-packages/middlewared/schema.py", line 977, in nf
          return f(*args, **kwargs)
        File "/usr/local/lib/python3.8/site-packages/middlewared/plugins/mail.py", line 424, in send_raw
          raise CallError(f'Failed to send email: {e}')
      middlewared.service_exception.CallError: [EFAULT] Failed to send email: [Errno 32] Broken pipe
      

      I wonder if it's still trying to use the OAuth API even though I have switched to SMTP in the configuration UI.

        Attachments

          Attachments

            JEditor

              Issue Links

                Activity

                  People

                  Assignee:
                  vladimirv Vladimir Vinogradenko
                  Reporter:
                  vpv Ville-Pekka Vainio
                  Votes:
                  0 Vote for this issue
                  Watchers:
                  4 Start watching this issue

                    Dates

                    Created:
                    Updated:
                    Resolved: