English 中文(简体)
企图在Ruby认证的员工和管理当局协调署
原标题:Attempt at authenticated SMTP in Ruby
  • 时间:2011-11-09 08:15:39
  •  标签:
  • ruby

我看看一下所有员工和管理当局协调会的废墟,可以发现我会错:

def send(username, password, data, toAddress, fromAddress)

    smtp = Net::SMTP.new( my.smtp.host , 25)
    smtp.start( thisisunimportant , username, password, "plain") do |sender|                                                                       
        sender.send_message(data, fromAddress, toAddress)
    end

end

send(user, pass, rcpt, "Hey!")

2. 产生出的错误:

/usr/lib/ruby/1.9.1/net/smtp.rb:725:in authenticate : wrong number of arguments (3 for 4) (ArgumentError) from /usr/lib/ruby/1.9.1/net/smtp.rb:566:indo_start from /usr/lib/ruby/1.9.1/net/smtp.rb:531:in start from gmx_pop.rb:24:insend from gmx_pop.rb:30:in `

我曾尝试过一次踢我的电脑,但问题依然存在。

最佳回答

The following s presentation of the Net:SMTP#start calls:

http://ruby-doc.org/stdlib-1.9.1/libdoc/net/smtp/rdoc/Net/SMTP.html#method-i-start/a。

该页提到,你只能做员工和管理当局协调会。 立即开始一切工作。

同你一样,看不到港口参数。 Try Port 587 for safety accreditation, if that don t work, Port 25. (教授如下)

您的号召就是:

message_body = <<END_OF_EMAIL
From: Your Name <[email protected]>
To: Other Email <[email protected]>
Subject: text message

This is a test message.
END_OF_EMAIL


server =  smtp.gmail.com 
mail_from_domain =  gmail.com 
port = 587      # or 25 - double check with your provider
username =  [email protected] 
password =  your_password 

smtp = Net::SMTP.new(server, port)
smtp.enable_starttls_auto
smtp.start(server,username,password, :plain)
smtp.send_message(message_body, fromAddress, toAddress)    # see note below!

Important:

  • Please note that you need to add To: , From: , Subject: headers to your message_body!
  • the Message-Id: and Date: headers will be added by your SMTP server

www.un.org/Depts/DGACM/index_spanish.htm 检查:


www.un.org/Depts/DGACM/index_spanish.htm 发出电子邮件的另一途径是。

You can use the ActionMailer gem from Rails to send emails from Ruby (without Rails). At first this seems like overkill, but it makes it much easier, because you don t have to format the message body with To: , From: , Subject: , Date: , Message-Id: Headers.

# usage:                                                                                                                                                                                               
#   include Email                                                                                                                                                                                       
#                                                                                                                                                                                                                                            
# TEXT EMAIL :   
#   send_text_email(  [email protected] ,  [email protected],[email protected] ,  test subject ,  some body text  )                                                               
# HTML EMAIL :
#   send_html_email(  [email protected] ,  [email protected],[email protected] ,  test subject ,  <html><body><h1>some title</h1>some body text</body></html>  )                  


require  action_mailer 

# ActionMailer::Base.sendmail_settings = {
#   :address => "Localhost",
#   :port => 25, 
#   :domain => "yourdomain.com"
# }

ActionMailer::Base.smtp_settings = {        # if you re using GMail
  :address              =>  smtp.gmail.com ,  
  :port                 => 587,  
  :domain               =>  gmail.com ,  
  :user_name            => "[email protected]"
  :password             => "your-password"
  :authentication       => "plain",  
  :enable_starttls_auto => true  
}

class SimpleMailer < ActionMailer::Base

  def simple_email(the_sender, the_recepients, the_subject, the_body , contenttype = nil)
    from the_sender
    recipients the_recepients
    subject the_subject
    content_type     contenttype ==  html  ?  text/html  :  text/plain 
    body the_body
  end
end

# see http://guides.rails.info/action_mailer_basics.html                                                                                                                                               
# for explanation of dynamic ActionMailer deliver_* methods.. paragraph 2.2                                                                                                                            

module Email
  # call this with a message body formatted as plain text                                                                                                                                              
  #                                                                                                                                                                                                    
  def send_text_email( sender, recepients, subject, body)
    SimpleMailer.deliver_simple_email( sender , recepients , subject , body)
  end

  # call this with an HTML formatted message body                                                                                                                                                      
  #                                                                                                                                                                                                    
  def send_html_email( sender, recepients, subject, body)
    SimpleMailer.deliver_simple_email( sender , recepients , subject , body,  html )
  end
endsubject , body,  html )
  end
end

例如,如果你想利用全球邮联的服务器通过电子邮件账户发送电子邮件,上述代码就可行。 其他员工和管理当局协调会服务器可能需要其他价值,用于:港口、:校正和:根据员工和管理当局协调会服务器的设置,可以启动。

问题回答

D. 守则

Net::SMTP.smtp.start( my.smtp.host , 25,  mail.from.domain , username, password, :plain) do |smtp|                                                                       
    smtp.send_message data, fromAddress, toAddress
end




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签