2013-10-28 210 views
0

设立所以我测试了红宝石的宝石'Mail'。以下是我的代码。根据系统管理员,有通过SMTP发送出无必要的认证和服务器所允许通过SMTP发送。如果这是有道理的。红宝石宝石“邮件”与SMTP

我已经使用'net/smtp'工作正常,但我似乎无法得到此'Mail'宝石为我工作。它不会给我任何错误,所以我不确定问题是什么。我是一个完整的红宝石小白。

#testing out mailer 
require 'mail' 
Mail.defaults do 
    delivery_method :smtp, { 
    :address => '10.18.34.18', 
    :port => '25', 
    :user_name => 'anonymous', 
    :password => 'anonymous', 
    :authentication => 'plain', 
    :enable_starttls_auto => true} 
end 

mail = Mail.new do 
    from '[email protected]' 
    to '[email protected]' 
    subject 'This is a test email' 
    body File.read('test.txt') 
end 

mail.to_s 

回答

1

尝试调用mail.deliver!,呼吁to_s只是返回你的对象的字符串表示。

备选地可以调用deliver与块而不是调用new,例如

mail = Mail.deliver do 
    from '[email protected]' 
    to '[email protected]' 
    subject 'This is a test email' 
    body File.read('test.txt') 
end 
0

除了什么struthersneil说,我不得不删除,像这样的认证:

require 'mail' 
Mail.defaults do 
    delivery_method :smtp, { 
    :address => '10.18.34.18', 
    :port => '25', 
    :enable_starttls_auto => true} 
end