Can't send emails over VPS
I use the lettre crate under the Rust programming language to send emails programmatically to new potential users to verify their email during account creation. When I run the program with my own computer it works flawlessly and properly sends an email out but when I try it with my VPS the code runs and finishes without showing any errors but doesn't send the email. I already talked with the people at Linode to allow outbound connections at port 25, 465, and 587 as well as allow the said ports with firewall so I know that's not the issue (I even turned off the firewall and ran the program but the email never gets sent). Why can't I send emails over my VPS? If you'd like to recreate what's happening on your computer simply install Rust and then get the proper code from https://github.com/CrimsonTide0/Email or just run the command: "git clone https://github.com/CrimsonTide0/Email" then cd into with "cd Email/src" and then "nano main.rs" then replace email with the email that's going to send the message, password with the associated password, and recipient_email with the email that's going to receive the message. Then run the program with "cargo run" You'll likely find that this works on your computer as well but on Linode it doesn't for some reason. Thanks in advance!
@CrimsonTide0 I'm sorry that you're having trouble sending mail with with lettre crate and Rust. There aren't any restrictions on Linode's end that would prevent you from being able to send emails, if you've already had the new account restrictions removed. That being said, it may be helpful to reach out to the Rust and community and review the lettre documentation to see if they are able to provide you with more details. These community members are users of these services and have first hand experience with common issues that may arise.
It may also be helpful to check the logs of the mail server application you are using on your Linode. The location of the logs will depend on the service you are using.
I hope this has been helpful, and feel free to reply with the output of any error messages you receive during your investigation. The link below provides some really useful things to keep in mind when asking any community for troubleshooting help.
So after giving up for a long time as I needed to focus on other things, I found out where the logs are and discovered that every time I try to send out an email through code I get the following logs:
globalfun postfix/smtps/smtpd: connect from localhost[::1]
globalfun postfix/smtps/smtpd: SSL_accept error from localhost[::1]: -1
globalfun postfix/smtps/smtpd: warning TLS library problem: error 14094418:SSL routines:ssl3_resl3_read_bytes: tlsv1 alert unknown ca:../ssl/rec/layer_s3.c:1543:SSL alert number 48:
globalfun postfix/smtps/smtpd: lost connection after CONNECT from localhost[::1]
globalfun postfix/smtps/smtpd: disconnect from localhost[::1] commands=0/0
So, apparently there's some problem with the SSL. Do you have any suggestions as to how I can fix this?
some problem with the SSL
Does the domain have a SSL certificate installed… i.e. Let's Encrypt/Certbot? Perhaps that is what is needed. Just a guess as running email via postfix, dovcot, etc., is beyond my pay grade! (I did have success with Mail-In-A-Box a couple of years ago.)
So I have 2 servers running on my VPS: one is for my website and the other is for my private mail server. The website does have a SSL certificate but the private mail server (cyberpanel/rainloop) does not. That said when I send a email manually through rainloop, the email gets sent. When I try to programmatically send an email through a Rust crate, the error log comes up. On my devices, the Rust program successfully sends out an email, but on the VPS - it doesn't.
So I have 2 servers running on my VPS: one is for my website and the other is for my private mail server. The website does have a SSL certificate but the private mail server (cyberpanel/rainloop) does not.
If the website and the mail server use the same domain, just use the web server one for the mail server. I've been doing this for years…
Just configure your email server to use the same cert, key & chain (or PEM) files your web server uses.
Also, to be a good netizen, you need to set up SPF, DKIM & DMARC or some of the big email providers will not deliver your mail. SPF is a near-universal requirement these days.
Consult the Google machine near you.