title: Send emails via CURL (shell script) CURL command returned 0 but the receiver didn't receive the attached files but the message
body: <p>I've run into a problem with sending emails via CURL using shell script.</p>
  <p>I have a script that do:</p>
  <ol>
  <li><p>Download dashboards from our Tableau server (private) via tabcmd command then save these files into a directory.</p>
  </li>
  <li><p>Send these files to receivers using a SMTP sever (private) via CURL. Both Tableau Server and SMTP server are installed on a container CENTOS 7. I have CURL version 7.29.</p>
  </li>
  </ol>
  <p>I have a list of dashboards and list of emails. For each dashboard (that has a unique URL), the script downloads the dashboard files and then send the files to receiver.</p>
  <p><strong>My problem is that for some receivers they received their attached files but others didn't</strong>. I checked the stdout of CURL command, it returned that</p>
  <pre><code> % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
  
    0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* About to connect() to services.xxxx.xx.xxxx.xxx port 25 (#0)
  *   Trying xxx.xxx.xxxx.xxx...
  * Connected to services.xxxx.xx.xxxx.xxx (xxx.xxx.xxx.xxx) port 25 (#0)
  &lt; 220 xxxxx.xxxxx.xxxx.xxxx ESMTP Postfix
  &gt; EHLO tableau
  &lt; xxxxx.xxxxx.xxxx.xxxx
  &lt; 250-PIPELINING
  &lt; 250-SIZE 10240000
  &lt; 250-VRFY
  &lt; 250-ETRN
  &lt; 250-STARTTLS
  &lt; 250-ENHANCEDSTATUSCODES
  &lt; 250-8BITMIME
  &lt; 250-DSN
  &lt; 250-SMTPUTF8
  &lt; 250 CHUNKING
  &gt; MAIL FROM:&lt;xxxxx@yyyy.email.com&gt;
  &lt; 250 2.1.0 Ok
  &gt; RCPT TO:&lt;xxxx@yyyy.hotmail.com&gt;
  &lt; 250 2.1.5 Ok
  &gt; DATA
  &lt; 354 End data with &lt;CR&gt;&lt;LF&gt;.&lt;CR&gt;&lt;LF&gt;
  } [data not shown]
  &lt; 250 2.0.0 Ok: queued as 2xxxxx
  
    0     0    0     0    0  130k      0  5735k --:--:-- --:--:-- --:--:-- 5932k
  * Connection #0 to host services.xxxx.xx.xxxx.xxx left intact 
  
  </code></pre>
  <p><strong>This means that the email is sent successfully with attached files. But the receiver didn't receive the attached files</strong>. I also checked that the files were in the directory.</p>
  <p>The code to send email is something like that:</p>
  <pre><code>send_pdf(){
     
      receiver=&quot;$1&quot;
      subject=&quot;$2&quot;
      message=&quot;$3&quot;
      num_file_attaches=$(expr $# - 3)
  
      eval body=$(cat parameters/data.txt)
  
      for file in &quot;${@:4}&quot;; do
          add_file &quot;$body&quot; &quot;$file&quot;
      done
  
      body+=&quot;--MULTIPART-MIXED-BOUNDARY--&quot;
      echo -e &quot;$body&quot; | curl -s &quot;$SMTP_SERVER&quot; \
          --mail-from &quot;$SENDER&quot; \
          --mail-rcpt &quot;$receiver&quot;\
          -T -
  
  }
  </code></pre>
  <p>and the function <strong>add_file</strong></p>
  <pre><code>add_file() {
      body=&quot;$1&quot;
      file_attach=&quot;$2&quot;
      name_file_attach=$(basename $file_attach)
      file_base64=$(cat $file_attach | base64)
  
      MIMEType=`file --mime-type &quot;$file_attach&quot; | sed 's/.*: //'`
      body+=&quot;--MULTIPART-MIXED-BOUNDARY\nContent-Type: $MIMEType;name=${name_file_attach}\nContent-Transfer-Encoding: base64\nContent-Disposition: attachment;filename=${name_file_attach}\n\n\n${file_base64}\n\n\n&quot;
  }
  </code></pre>
  <p>For each time I test with my emails, the script works but when I replace my email by those of clients, there are always some clients who didn't receive attached files. However, these clients received the message.</p>
  <p>I can't do some tests with emails of clients :( So, I can't reproduce the problem.</p>
  <p><strong>Does anyone have any idea where the problem could come from or how can I reproduce the problem?</strong></p>
  <p>Many thanks,</p>