I'm trying to send emails from a rails application using smtp. Sending the emails does not cause problems, but some recipients do not receive the emails. Instead, delivery notices ("Undelivered Mail Returned to Sender") are returned with:
Diagnostic-Code: smtp; 554 5.7.0 Reject, id=04635-09 - spam: This message was
blocked for security reasons
Now the strange part:
- Sending a test mail through a mail client via smtp (TLS/SSL true, port 465, auth: password) works. The recipient receives the email without error.
- Sending the email via
sendemail -o tls=yes -f [email protected] -t [email protected] -s 212-227-10-158.benjaminkant.de -xu [email protected] -xp password -u "Hello from sendemail" -m "This is a test." -vvvvworks. The recipient receives the email without error. Sending the email through the mail gem (which is what I want to achieve) using the same smtp account works, but the recipient does not receive the email. Instead, "Undelivered Mail Returned to Sender" is sent to the sender address.
require 'mail' options = {address: "212-227-10-158.benjaminkant.de", user_name: "[email protected]", password: "...", authentication: "login"} Mail.defaults { delivery_method :smtp, options } message = Mail.new(to: "[email protected]", from: "[email protected]", subject: "Test", body: "This is a test.") message.deliverAlso, I've tried these options, resulting in the same issue:
options = {address: "212-227-10-158.benjaminkant.de", user_name: "[email protected]", password: "...", authentication: "login"} options = {address: "212-227-10-158.benjaminkant.de", user_name: "[email protected]", password: "...", authentication: "login", enable_starttls_auto: true} options = {address: "212-227-10-158.benjaminkant.de", user_name: "[email protected]", password: "...", authentication: "login", port: 465, enable_starttls_auto: false, ssl: true} options = {address: "212-227-10-158.benjaminkant.de", user_name: "[email protected]", password: "..."}
Does this make sense to anyone?
Additional information
MX records
▶ host -t MX fiedlschuster.de
fiedlschuster.de mail is handled by 10 mail.fiedlschuster.de.
▶ host -t MX 212-227-10-158.benjaminkant.de
212-227-10-158.benjaminkant.de has no MX record
Firstly, it's worth checking
message.to_sThe only thing that screams out at me is the Message-ID - it uses your machine name. It's possible that some spam filters compare this to the sender's domain name, and if they don't match, assume that you are a bot?
(I don't know what
sendemaildoes here, but my Thunderbird certainly uses my domain name)So I'd try: