Назад | Перейти на главную страницу

Почтовый SMTP-сервер с Nodemailer, NGINX и Namecheap

Я пытался настроить NGINX для отправки электронной почты из моей контактной формы через nodemailer и privateemail.com. Пока мне не повезло. Кажется, я сузил его до nginx. У меня есть порты 465, 25 и 587, открытые через брандмауэр ufw. Я использую digitalocean с ubuntu 20.04. Любое понимание будет оценено.

Спасибо.

APP.JS

var express             = require('express'),
        bodyParser      = require('body-parser'),
        nodemailer      = require('nodemailer'),
        path            = require('path'),
        app             = express();

//Set View Engine to use EJS
app.set('view engine', 'ejs');
//Setting up body-parser
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
// Public directory config
app.use(express.static(path.join(__dirname, '/public')));

app.get('/', function(req, res){
        res.render('index');
});

app.get('/about', function(req, res){
        res.render('about');
});
app.get('/portfolio', function(req, res){
        res.render('portfolio');
});
app.get('/contact', function(req, res){
        res.render('contact');
});

let transporter = nodemailer.createTransport({
    host: "mail.privateemail.com",
    port: 25,
    secure: false,
    auth: {
      user: 'username@example.com',
      pass: 'password'
    },
  });

app.post('/send', function(req, res){
transporter.sendMail({
    from: '"Fred Foo 👻" <changed for privacy>', // sender address
    to: "changed for privacy", // list of receivers
    subject: "Hello ✔", // Subject line
    text: "Hello world?", // plain text body
    html: "<b>Hello world?</b>", // html body
  });
        res.redirect('/');
});

app.listen(3000, function(){
        console.log('Server listening on port 3000...');
});

/ и т.д. / nginx / сайты-включены / по умолчанию


server {
        listen 443 ssl;
        listen [::]:443 ssl;

        ssl_certificate /etc/nginx/ssl/cardinaldesign_dev.crt;
        ssl_certificate_key /etc/nginx/ssl/cardinaldesign.dev.key;

        ssl_session_cache builtin:1000 shared:SSL:10m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;

        root /var/www/html;

        index index.html index.htm index.nginx-debian.html;

        server_name cardinaldesign.dev www.cardinaldesign.dev;

        location / {
                proxy_pass http://localhost:3000/;
                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_read_timeout 90;
                proxy_redirect http://localhost:3000/ https://cardinaldesign.dev;
        }

        location /send {
                proxy_bind 161.35.111.103;
                proxy_pass http://localhost:3000;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }
}

/etc/nginx/nginx.conf

mail {
        server_name mail.privateemail.com;
        auth_http localhost:3000/cgi-bin/nginxauth.cgi;
        proxy_pass_error_message on;
        starttls on;
        ssl_certificate /etc/nginx/ssl/cardinaldesign_dev.crt;
        ssl_certificate_key /etc/nginx/ssl/cardinaldesign.dev.key;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_session_timeout 10m;
        server {
                listen     25;
                protocol   smtp;
                smtp_auth login plain cram-md5;
        }
}