(Ruby)正在使用Net :: SMTP与Gmail合作...? [英] (Ruby) Getting Net::SMTP working with Gmail...?

查看:102
本文介绍了(Ruby)正在使用Net :: SMTP与Gmail合作...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于使用Ruby的Net :: SMTP通过Gmail发送邮件的任何人,是否有任何质量(最新)信息?我看过几个例子,其中大多数可追溯到2007年到2008年中期,但没有一个对我有用。我需要更多使用最新1.8.7版本的示例。如果文档中仅涵盖了没有人真正使用过的简单示例,我也将不胜感激。

Does anyone have any quality (and up-to-date) information regarding sending mail via Gmail using Ruby's Net::SMTP? I've seen several examples -- most dating from 2007 to mid-2008 and none of them work for me. I need more current examples that use the most recent 1.8.7 release. I'd also appreciate if the documentation didn't only cover simple examples that no one ever really uses.

当前,我收到一个错误消息:

Currently I'm receiving an error:

 SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol

关于SMTP协议,我对SSL并不十分熟悉,所以这一切对我来说都是迷路。不幸的是,Net :: SMTP文档仅涵盖了基础,也没有提供各种潜在的OpenSSL :: SSL上下文的完整列表,因此我无法尝试使用各种上下文。

I'm not terribly familiar with SSL as regards the SMTP protocol, so this is all lost on me. Unfortunately the Net::SMTP documentation only covers the bases and doesn't provide a full list of the various potential OpenSSL::SSL contexts either so I can't try various ones.

无论如何,如果有人对将其与Gmail配合使用有任何质量方面的信息,将不胜感激。

Anyway, if anyone has any quality info on getting this to work with Gmail it would be most appreciated.

最好。

推荐答案

我实际上刚刚开始工作。

I actually just got this working. Wrote a quick script to test it.

我遇到的错误与您遇到的错误不同(需要STARTTLS),我还发现我必须使用端口587而不是465。

I was getting a different error than you were (requiring STARTTLS), I also found I had to use port 587 instead of 465.

我找到了使之在我发现的Rails插件中运行的技巧。 (agilewebdevelopment.com/plugins/net_smtp_tls_support)

I found the trick to get it working in a Rails plugin I found. (agilewebdevelopment.com/plugins/net_smtp_tls_support)

如果您评估此文件(它将tls支持添加到标准Net :: SMTP库中):

if you 'eval' this file (it adds tls support to the standard Net::SMTP library):


http://happiness-is-slavery.net/wp-content/rails-plugins/smtp_add_tls_support/lib/smtp_add_tls_support.rb

然后运行'Net :: SMTP.enable_tls()'

then run 'Net::SMTP.enable_tls()'

一切似乎都正常。

这是我的代码:

require 'rubygems'
require 'net/smtp'

eval File.read("smtp_tls.rb")
Net::SMTP.enable_tls() 
FROM_EMAIL = "REMOVED"
PASSWORD = "REMOVED"
TO_EMAIL = "REMOVED"

msgstr = <<END_OF_MESSAGE
From: Your Name <#{FROM_EMAIL}>
To: my phone <#{TO_EMAIL}>
Subject: text message
Date: Sat, 23 Jun 2001 16:26:43 +0900
Message-Id: <unique.message.id.string@example.com>

This is a test message.
END_OF_MESSAGE

Net::SMTP.start('smtp.gmail.com', 587, 'gmail.com',
                      FROM_EMAIL, PASSWORD, :plain) do |smtp|
  smtp.send_message msgstr, FROM_EMAIL, TO_EMAIL

end

显然,我将上述文件下载到了同一目录,并将其命名为 smtp_tls.rb。

obviously, i downloaded the above mentioned file to the same directory and named it 'smtp_tls.rb'

希望这会有所帮助!

这篇关于(Ruby)正在使用Net :: SMTP与Gmail合作...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆