Cannot send emails with SMTP

Hey all, apologies for the possibly stupid question. I’ve searched high and low and nobody seems to be having this same issue, except for people who haven’t configured their stmp setup, but I definitely have. My issue is that I’m not able to send emails. I’ve tried two separate email sending providers (Postmark and Sendinblue) and neither of them ever see any emails. It’s as if I’m not configured, but I am and I can’t figure out for the life of me what I’m doing wrong. Sendinblue could not be any easier, it only gives me four variables to enter: hostname, port, username, and password. Postmark isn’t much harder. I’ve tried leaving the sendmail field empty, I’ve tried false, I’ve tried true, I’ve tried tls false, I’ve tried disable_starttls true, I have no idea why it’s not working. Here’s my smtp config below. If anybody could help me, that’d be amazing. I’m at my wit’s end trying to figure out why it’s not working.

# SMTP server to send emails
smtp:
  # smtp or sendmail
  transport: smtp
  # Path to sendmail command. Required if you use sendmail transport
  sendmail: false
  hostname:  smtp-relay.sendinblue.com
  port: 587
  username: [redacted]
  password: [redacted]
  tls: true # If you use StartTLS: false
  disable_starttls: false
  ca_file: null # Used for self signed certificates
  from_address: 'no-reply@apertatube.net'

When you (re)start Peertube, you should see some logs concerning the SMTP connection. Can you check them?

If you don’t want to restart Peertube, you can try:

cd /var/www/peertube/storage/logs # adapt if you have a different installation path
rgrep SMTP

You should find something like this:

peertube11.log:{"level":"info","message":"Using [redacted]:465 as SMTP server.","label":"videos.john-livingston.fr:443","timestamp":"2022-03-29T07:44:09.479Z"}

In your case, you will probably find error logs.

Or you can restart Peertube and check the system logs:

systemctl restart peertube
journalctl -feu peertube

I think you can try the port 465.

I ran the « rgrep SMTP » command you suggested and here was the output. I see something about « wrong version number » and SSL but honestly I’m not skilled enough to make sense of what it’s trying to tell me.

peertube.log:{"level":"info","message":"Using smtp.postmarkapp.com:587 as SMTP server.","label":"apertatube.net:443","timestamp":"2022-07-24T23:17:46.576Z"}
peertube.log:{"message":"Testing SMTP server...","level":"info","label":"apertatube.net:443","timestamp":"2022-07-24T23:17:46.580Z"}
peertube.log:{"level":"error","message":"Failed to connect to SMTP smtp.postmarkapp.com:587.","label":"apertatube.net:443","err":{"stack":"Error: 140011426563968:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:\n","message":"140011426563968:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:\n","library":"SSL routines","function":"ssl3_get_record","reason":"wrong version number","code":"ESOCKET","command":"CONN"},"timestamp":"2022-07-24T23:17:47.017Z"}
peertube1.log:{"level":"info","message":"Using smtp-relay.sendinblue.com:587 as SMTP server.","label":"apertatube.net:443","timestamp":"2022-08-07T20:05:58.930Z"}
peertube1.log:{"message":"Testing SMTP server...","level":"info","label":"apertatube.net:443","timestamp":"2022-08-07T20:05:58.934Z"}
peertube1.log:{"level":"error","message":"Failed to connect to SMTP smtp-relay.sendinblue.com:587.","label":"apertatube.net:443","err":{"stack":"Error: 140282792261504:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:\n","message":"140282792261504:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:\n","library":"SSL routines","function":"ssl3_get_record","reason":"wrong version number","code":"ESOCKET","command":"CONN"},"timestamp":"2022-08-07T20:05:59.295Z"}

Hello,

Your shared log extract refers to « smtp.postmarkapp.com » while the peertube configuration defines « smtp-relay.sendinblue.com ». There is confusion there.

Now, referring to your log, I think you should get the user and password from SMTP settings within your PostMarkApp account (cf. Sending email with SMTP | Postmark Developer Documentation)

After your message, I did some digging to figure out why that was. Long story short: it looks like my issue is some sort of « SSL3 wrong version » error as noted in the final line. Has anyone seen this before or know how I can fix it?

Have you tried using the port 465, as I suggested above?
I think you are trying to connect using TLS on a port that does not use TLS.

Tried Port 465 just now and still no dice. Postmark recommends ports 25, 2525, and 587 and my research suggested the first two were not good choices.

Maybe by settings tls to false?

If it does not work, here is another lead:

The library used by Peertube is nodemailer:

Note: the Peertube configuration «smtp.tls» is the secure parameter in the above code.

Check this on nodemailer page: I get TLS errors.

I’m sorry for the late reply. I got really busy at work and then I tried to hire someone to do this for me and they somehow ended up irreversibly 502’ing my entire instance. I’ve regained control and got the instance back up, but still having mailer issues.

Do you happen to know where the nodemailer settings are in PeerTube? This does seem like a promising lead based on your links, but I’m not sure where to go change settings.

In the above Peertube code, when you see something like CONFIG.SMTP.HOSTNAME, it means it comes from smtp: hostname in the config file. The mapping is done here:

The config.get method reads the config value in the yaml files.

But maybe the problem is the provider. I don’t know sendinblue, but it sound like this is a marketing solution. Maybe this is not very good for your users privacy?
There are many easy solution to send mails. From installing postfix or exim4 on your server, to use the mailboxes that comes with your domain name (many registrar are offering one or two mailboxes, or even a full SMTP server).

Holy crap I finally got it. It was a nodejs version issue. The official instructions say to use Node 14.x. I posted in a self-hosting Matrix room and someone else said they use Node 16 without issue, so I upgraded and it just magically started working. Gonna report that and suggest updating the documentation.

Thank you so much for your help, John. I wouldn’t have suspected node if it weren’t for your nodemailer lead and links. Thanks everyone who helped, I’ve been losing my mind over this for weeks.

That’s weird, Peertube 4.2.2 is compatible with node 14. That’s the version I’m using on at least 3 different instances, and everything works. Do you know the exact issue? Is this related to your mail provider?

If by mail provider you mean Postmark, I don’t think so. Again, I tried a different provider and also ran into the same issue. And once I updated to Node 14, it just instantly started working. I didn’t even have to do a reboot or anything, I actually hit a button by accident and suddenly an email popped into my inbox. I’m not sure why it works for you but not me, but personally that was my issue was I needed a newer version of Node. As for the exact issue, I’m not sure. I think it’s related to the « SSL3 wrong version » error I mentioned above, and then coupled with the nodemailer FAQ page you sent me, it mentioned that lower versions of node may have compatibility issues, so based on that (and the feedback on Matrix) I took an educated guess and updated.