J'essaie d'envoyer un exemple d'e-mail depuis mon application rails.comment envoyer un e-mail depuis l'application rails avec l'adresse gmail
ce que je l'ai fait jusqu'à présent:
rails gmailtest
cd gmailtest
script/plugin install git://github.com/collectiveidea/action_mailer_optional_tls.git
Puis je posai la suite dans mon dossier environment.rb
(après 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
ensuite placé à la suite 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
Placé à views\user_mailer\welcome_email.text.html.erb
<!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>
Essayé d'envoyer un courriel!
>> UserMailer.deliver_welcome_email("[email protected]")
=> #<TMail::Mail port=#<TMail::StringPort:id=0x4bf7c42> bodyport=#<TMail::StringPort:id=0x4bd4c1a>>
Maintenant, je ne sais pas si la configuration fonctionne ou non? puis-je envoyer un exemple d'e-mail à partir de l'invite de commande (script/console
) pour m'assurer que la configuration fonctionne?
Également dans la section de domaine J'ai juste mon email. Est-ce correct ou dois-je avoir un domaine de google? Il n'envoie pas d'e-mail.