2
我想从我的Rails应用程序发送示例电子邮件。如何从Rails应用程序发送电子邮件与Gmail地址
这是我迄今所做的:
rails gmailtest
cd gmailtest
script/plugin install git://github.com/collectiveidea/action_mailer_optional_tls.git
然后我把我的environment.rb
文件之后(后end
)
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "[email protected]",
:user_name => "[email protected]",
:password => "mypwd",
:authentication => :plain
}
script/generate mailer UserMailer
然后放置在以下models\UserMailer
:
class UserMailer < ActionMailer::Base
def welcome_email(email)
recipients email
from "My Awesome Site Notifications <[email protected]>"
subject "Welcome to My Awesome Site"
sent_on Time.now
#body {:user => "", :url => "http://example.com/login"}
end
end
放置在之后
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<h1>Welcome to example.com, </h1>
<p>
You have successfully signed up to example.com, and your username is:.<br/>
To login to the site, just follow this link:.
</p>
<p>Thanks for joining and have a great day!</p>
</body>
</html>
尝试发送电子邮件!
>> UserMailer.deliver_welcome_email("[email protected]")
=> #<TMail::Mail port=#<TMail::StringPort:id=0x4bf7c42> bodyport=#<TMail::StringPort:id=0x4bd4c1a>>
现在我不知道该设置是否工作或没有?我可以从命令提示符(script/console
)发送示例电子邮件以确保设置正常工作吗?
此外,在域部分,我只是有我的电子邮件。这是好的,还是我需要从谷歌有一个域名?
它不发送电子邮件