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