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
)發送示例電子郵件以確保設置正常工作嗎?
此外,在域部分,我只是有我的電子郵件。這是好的,還是我需要從谷歌有一個域名?
它不發送電子郵件