使用Bamboo发送邮件报错:DigitalOcean Droplet邮件服务器Postfix正常但适配器异常
Hey there! Let's figure out why your Bamboo SMTP setup is failing when the system-level mail command works perfectly on your DigitalOcean Droplet. Here are the most common issues and how to fix them:
The mail command uses Postfix's local delivery (often via Unix socket or trusted localhost access), but Bamboo connects over TCP—so mismatches here are the first thing to check:
- Server & Port: Ensure your Bamboo config points to
localhost(or127.0.0.1) and the correct port. Postfix typically listens on port 25 for local unauthenticated traffic, or 587 for submission with authentication. Double-check yourconfig/config.exs(or runtime config) for:config :my_app, MyApp.Mailer, adapter: Bamboo.SMTPAdapter, server: "localhost", port: 25, # ... other settings - Authentication: The
mailcommand skips auth because it's a local system user, but if Postfix hassmtpd_sasl_auth_enable = yesinmain.cf, you need to add valid credentials to Bamboo (matching Postfix's SASL users). If auth isn't required, setusername: nilandpassword: nil. - TLS Settings: If Postfix doesn't enforce TLS on port 25, setting
tls: :alwaysin Bamboo will cause errors. Trytls: :neverfirst for testing, or align it with Postfix'ssmtpd_tls_security_levelvalue inmain.cf.
Postfix might be blocking Bamboo's connection even though it lets the mail command through:
mynetworksConfiguration: In/etc/postfix/main.cf, make suremynetworksincludes127.0.0.1/32(localhost). This tells Postfix to trust connections from the local machine without auth. If it's missing, add it:mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128- Recipient Restrictions: Ensure
smtpd_recipient_restrictionsinmain.cfhaspermit_mynetworkslisted before restrictive rules likereject_unauth_destination. This ensures local connections are allowed first.
Get concrete details about what's failing:
- Enable Bamboo Debugging: Add
debug: trueto your Bamboo config. This will print the full SMTP conversation in your logs, showing exactly where the error occurs (e.g., EHLO rejection, auth failure). - Check Postfix Logs: Run
tail -f /var/log/mail.log(on Debian/Ubuntu) while trying to send via Bamboo. The logs will show Postfix's exact reason for rejecting the connection—look for lines likeClient rejected: Access deniedorSASL authentication failed.
Rule out Bamboo-specific issues by simulating the connection yourself:
Use telnet or nc to connect to Postfix directly:
telnet localhost 25 # Once connected: EHLO localhost MAIL FROM:<your_local_user@your_droplet_domain> RCPT TO:<your_email_address> DATA Subject: Manual SMTP Test This is a test email sent directly via SMTP . QUIT
If this manual test fails, the problem is in Postfix's configuration. If it succeeds, double-check every parameter in your Bamboo config for typos or mismatches.
内容的提问来源于stack exchange,提问作者Sh4dy

