title: Nuxt-mail not sending email when I use nginx
body: <p>I have a Nuxtjs app running on my VPS in my Docker containers with nginx. I need to send form in email and I'm using nuxt-mail (lib for nuxt using nodemailer) for it. In dev it worked fine without nginx and domain, I sent forms directly on <code>IP.of.VPS/mail/send/</code> and it was ok.</p>
  <p>Now in production when I'm trying to send mail I have CORS or preflight errors, depends on which address I'm trying to send. I tried a lot options: tried to send on http, https, tried using domain name and IP address of my VPS and it doesn't work.</p>
  <p><strong>I have next nginx configs (part with conditions i took from this <a href="https://enable-cors.org/server_nginx.html" rel="nofollow noreferrer">website</a> trying to fix CORS errors):</strong></p>
  <pre><code>
      server {
          listen      80;
          listen [::]:80;
          server_name studioagnc.com;
      
          location / {
              rewrite ^ https://$host$request_uri? permanent;
              add_header 'Access-Control-Allow-Origin' '*' always;
              add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
              add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
              add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
          }
      
          location /mail/send {
              if ($request_method = 'OPTIONS') {
                  add_header 'Access-Control-Allow-Origin' '*';
                  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                  add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                  add_header 'Access-Control-Max-Age' 1728000;
                  add_header 'Content-Type' 'text/plain; charset=utf-8';
                  add_header 'Content-Length' 0;
                  return 204;
              }
              if ($request_method = 'POST') {
                  add_header 'Access-Control-Allow-Origin' '*' always;
                  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
                  add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
                  add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
              }
              if ($request_method = 'GET') {
                  add_header 'Access-Control-Allow-Origin' '*' always;
                  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
                  add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
                  add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
              }
          }
      
          location ^~ /.well-known {
              allow all;
              root  /data/letsencrypt/;
          }
      }
      
      server {
          listen      443           ssl http2;
          listen [::]:443           ssl http2;
          server_name               studioagnc.com;
      
          ssl                       on;
      
          add_header                Strict-Transport-Security &quot;max-age=31536000&quot; always;
      
          ssl_session_cache         shared:SSL:20m;
          ssl_session_timeout       10m;
      
          ssl_protocols             TLSv1 TLSv1.1 TLSv1.2;
          ssl_prefer_server_ciphers on;
          ssl_ciphers               &quot;ECDH+AESGCM:ECDH+AES256:ECDH+AES128:!ADH:!AECDH:!MD5;&quot;;
      
          ssl_stapling              on;
          ssl_stapling_verify       on;
          resolver                  8.8.8.8 8.8.4.4;
      
          ssl_certificate           /etc/letsencrypt/live/studioagnc.com/fullchain.pem;
          ssl_certificate_key       /etc/letsencrypt/live/studioagnc.com/privkey.pem;
          ssl_trusted_certificate   /etc/letsencrypt/live/studioagnc.com/chain.pem;
      
          access_log                /dev/stdout;
          error_log                 /dev/stderr info;
          
          # other configs
          location / {
              add_header 'Access-Control-Allow-Origin' '*' always;
              add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
              add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
              add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
              proxy_set_header Host $host;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header X-Forwarded-Proto $scheme;
              proxy_redirect    off;
              proxy_pass         http://nuxt_app:3000;
          }
      
          location /mail/send/ {
              if ($request_method = 'OPTIONS') {
                  add_header 'Access-Control-Allow-Origin' '*';
                  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                  add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                  add_header 'Access-Control-Max-Age' 1728000;
                  add_header 'Content-Type' 'text/plain; charset=utf-8';
                  add_header 'Content-Length' 0;
                  return 204;
              }
              if ($request_method = 'POST') {
                  add_header 'Access-Control-Allow-Origin' '*' always;
                  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
                  add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
                  add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
              }
              if ($request_method = 'GET') {
                  add_header 'Access-Control-Allow-Origin' '*' always;
                  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
                  add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
                  add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
              }
          }
      }
  
  </code></pre>
  <p><strong>Part of my Nuxt component where I'm trying to send form:</strong></p>
  <pre><code>
      submit() {
            this.$axios.$post(&quot;/mail/send&quot;, {
              from: &quot;studioagnc_redirect@mail.ru&quot;,
              subject: &quot;Заказ AGNC&quot;,
              html: `&lt;h2 style='color:#9389d2; margin-bottom: 0.3em'&gt;Имя заказчика:&lt;/h2&gt;
              &lt;p style='margin: 0 0'&gt;${this.userName}&lt;/p&gt;
              &lt;h2 style='color:#9389d2; margin-bottom: 0.3em'&gt;Почта заказчика:&lt;/h2&gt;
              &lt;p style='margin: 0 0'&gt;${this.userMail}&lt;/p&gt;
              &lt;h2 style='color:#9389d2; margin-bottom: 0.3em'&gt;Услуги: &lt;/h2&gt;
              &lt;ul&gt;${String(
                this.value.map(el =&gt; {
                  return `&lt;li&gt;${el.name}&lt;/li&gt;` + &quot;\n&quot;;
                })
              ).replaceAll(&quot;,&quot;, &quot;&quot;)}&lt;/ul&gt;
              &lt;h2 style='color:#9389d2; margin-bottom: 0.3em'&gt;Описание:&lt;/h2&gt;
              &lt;p style='margin: 0 0'&gt;${this.userDetails}&lt;/p&gt;`
            });
          }
  
  </code></pre>
  <p><strong>My <code>nuxt.config.js</code> file:</strong></p>
  <pre><code>
      modules: [
          &quot;@nuxtjs/axios&quot;,
          [
            &quot;nuxt-mail&quot;,
            {
              message: {
                to: &quot;studioagnc_redirect@mail.ru&quot;
              },
              smtp: {
                host: &quot;smtp.mail.ru&quot;,
                port: 465,
                secure: true,
                auth: {
                  user: &quot;studioagnc_redirect@mail.ru&quot;,
                  pass: &quot;secret_key&quot;
                }
              }
            }
          ]
        ],
      
        axios: {
          baseURL: &quot;https://195.140.147.103&quot;
        }
  
  </code></pre>
  <p>Current console output:
  <a href="https://i.stack.imgur.com/LS7K7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LS7K7.png" alt="console output" /></a>
  Network tab:
  <a href="https://i.stack.imgur.com/47yuq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/47yuq.png" alt="network tab output" /></a>
  Error detail:
  <a href="https://i.stack.imgur.com/jQnBA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jQnBA.png" alt="error detail" /></a></p>
  <p>If it's important IP of my VPS is <code>195.140.147.103</code> and domain is <a href="https://studioagnc.com/" rel="nofollow noreferrer">https://studioagnc.com/</a></p>
  <p>What should I do in nginx configs to make it work properly?</p>