【问题标题】:Ruby Mail gem, how to script mail messagesRuby Mail gem,如何编写邮件消息脚本
【发布时间】:2011-05-17 23:45:57
【问题描述】:

我在 CENTOS 5 VM 上安装了 testmail.rb,SELinux 许可且 IPtables 关闭:

require 'rubygems'
require 'mail'

options = { :address              => "mail.domain.com",
            :port                 => 466,
            :domain               => 'otherdomain.com',
            :user_name            => 'somedude@domain.com',
            :password             => 'topsecret',
            :authentication       => 'plain',
            :enable_starttls_auto => true  }
 Mail.defaults do
  delivery_method :smtp, options
end

 mail = Mail.new do
      from 'somedude@otherdomain.com'
        to 'admin@domain.com'
   subject 'This is a test email'
      body File.read('body.txt')
 end

puts mail.to_s

脚本运行的结果是这样的:

Date: Tue, 30 Nov 2010 12:12:58 -0500
From: somedude@otherdomain.com
To: admin@domain.com
Message-ID: <4cf5309a2f074_284015c5c4de91b8270b2@apvdbs03.3rdomain.local.mail>
Subject: This is a test email
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

test!

“测试!”是body.txt的内容。

没有电子邮件到达发送到的帐户。我们从发送给域管理员的 smtp 设置。我使用 telnet 成功在未加密端口 (25) 上向域发送了一封电子邮件,但没有收到来自加密端口 (466) 的响应,可能是因为我的 telnet 会话未加密?

我可以通过哪些方式查看脚本执行期间发生的情况以进行故障排除?

更新: 尝试重定向:> log.log 2>&1,但没有提供任何额外信息。

【问题讨论】:

    标签: ruby email smtp centos5


    【解决方案1】:

    您错过了实际发送的线路。尝试添加

    mail.deliver!
    

    到脚本的结尾。

    【讨论】:

      猜你喜欢
      • 2016-08-10
      • 1970-01-01
      • 2014-11-28
      • 1970-01-01
      • 2017-02-27
      • 2011-11-02
      • 2012-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多