0

我正在尝试使用 smtp 从 Rails 应用程序发送电子邮件。发送电子邮件不会导致问题,但某些收件人不会收到电子邮件。相反,送达通知(“退回给发件人的未送达邮件”)与以下内容一起返回:

Diagnostic-Code: smtp; 554 5.7.0 Reject, id=04635-09 - spam: This message was
   blocked for security reasons

现在奇怪的部分:

  • 通过邮件客户端通过 smtp(TLS/SSL true,端口 465,auth:密码)发送测试邮件有效。收件人收到没有错误的电子邮件。
  • sendemail -o tls=yes -f foo@fiedlschuster.de -t bar@example.com -s 212-227-10-158.benjaminkant.de -xu foo@fiedlschuster.de -xp password -u "Hello from sendemail" -m "This is a test." -vvvv通过作品发送电子邮件。收件人收到没有错误的电子邮件。
  • 使用相同的 smtp 帐户通过邮件 gem发送电子邮件(这是我想要实现的)有效,但收件人没有收到电子邮件。而是将“未投递的邮件退回给发件人”发送到发件人地址。

    require 'mail'
    
    options = {address: "212-227-10-158.benjaminkant.de", user_name: "foo@fiedlschuster.de",
        password: "...", authentication: "login"}
    
    Mail.defaults { delivery_method :smtp, options }
    
    message = Mail.new(to: "bar@example.com", from: "foo@fiedlschuster.de",
        subject: "Test", body: "This is a test.")
    message.deliver
    

    另外,我尝试了这些选项,导致同样的问题:

    options = {address: "212-227-10-158.benjaminkant.de", user_name: "foo@fiedlschuster.de",
        password: "...", authentication: "login"}
    
    options = {address: "212-227-10-158.benjaminkant.de", user_name: "foo@fiedlschuster.de",
        password: "...", authentication: "login",
        enable_starttls_auto: true}
    
    options = {address: "212-227-10-158.benjaminkant.de", user_name: "foo@fiedlschuster.de",
        password: "...", authentication: "login",
        port: 465, enable_starttls_auto: false, ssl: true}
    
    options = {address: "212-227-10-158.benjaminkant.de", user_name: "foo@fiedlschuster.de",
        password: "..."}
    

这对任何人都有意义吗?

附加信息

MX 记录

▶ 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
4

1 回答 1

0

首先,值得检查message.to_s

Date: Wed, 24 Jul 2019 17:15:08 +0100
From: foo@fiedlschuster.de
To: bar@example.com
Message-ID: <5d38840ce52e9_5a6a2af20734c5b418642@my-machine-name.mail>
Subject: Test
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
 Content-Transfer-Encoding: 7bit

This is a test.

唯一对我大喊大叫的是 Message-ID - 它使用您的机器名称。一些垃圾邮件过滤器可能会将其与发件人的域名进行比较,如果它们不匹配,则假设您是机器人?

(我不知道sendemail这里是做什么的,但我的 Thunderbird 肯定使用我的域名)

所以我会尝试:

message = Mail.new(to: "bar@example.com", from: "foo@fiedlschuster.de",
    subject: "Test", body: "This is a test.", message_id: "#{Mail.random_tag}@fiedlschuster.de")
于 2019-07-24T16:27:46.703 回答