0% found this document useful (0 votes)
101 views4 pages

Project Name - : Mailing

This document describes how to build a simple mailing application using Ruby on Rails that allows a user to submit their name and email and sends a confirmation email using ActionMailer. It involves generating a users scaffold, adding the mail gem, generating a UserMailer, creating email views, and configuring delivery in the UsersController. Key steps include setting up an initializer for mail configuration, adding headers and delivery methods, and customizing views and routes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views4 pages

Project Name - : Mailing

This document describes how to build a simple mailing application using Ruby on Rails that allows a user to submit their name and email and sends a confirmation email using ActionMailer. It involves generating a users scaffold, adding the mail gem, generating a UserMailer, creating email views, and configuring delivery in the UsersController. Key steps include setting up an initializer for mail configuration, adding headers and delivery methods, and customizing views and routes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 4

Project Name - mailing

Thisisasimpleapplicationsimilartoourpreviousproject
SimpleApplication_BlogbuthereweaddaextrafeatureAnewuserputs
his/hernameandemailaddressandsubmitsit.Thenaconfirmationmailgetssent
totheusersemailid.ActionMailerallowsyoutosendemailsfromyour
applicationusingamailermodelandviews.
FirstcreateanewrailsappcalledMailing,likewedidbefore,andthenswitchto
therootdirectoryofthatapp.
Then,likeSimpleApplication_Blogprojectwegeneratescaffold.
$railsgscaffoldusersname:stringemail:string
andthenrunthecommand
$rakedb:migrate
Now,Wejustdosomeextrasteps

1.Intheconfig/initializersfolderwecreateafilesetup_mail.rbandaddsome
code.(Seethefilefordetails).

2.AddmailgemtoourGemfile
gemmail

3.Runthecommand
$bundleinstall

4.Noweverythingisconfiguredproperly,wegenerateanewmailer

$railsgmaileruser_mailer
Itcreatedanewuser_mailerclassatapp/mailersdirectory.
5.app/mailers/user_mailer.rbcontainsanemptymailer.Letsaddamethodcalled
registration_confirmation,thatwillsendanemailtotheusersregisteredemail
address(Seethefilefordetails).
6.Wecancreateanewviewforemailundertheapp/views/user_mailerdirectory.
Wecallitregistration_confirmation.text.erb.Wecansayanythingthatwewant
anditappearasthebodyoftheemail.
7.Forsendingthemail,weaddalineinusers_controller.rbfile(Seetheproject
filefordetails.)
UserMailer.registration_confirmation(@user).deliver

8.Wecanspecifyrootofoursitebymodifyingroutes.rbfile.

9.NowIfyourunthecommand
$railsserver
andinyourbrowseraddressbartypetheurlhttp://localhost:3000.youcansee
ourapp.

Someimportantthings
>>delivermethodsendstheemail
>>mail(headers={},&block)public

Themainmethodthatcreatesthemessageandrenderstheemailtemplates.There
aretwowaystocallthismethod,withablock,orwithoutablock.
Bothmethodsacceptaheadershash.Thishashallowsyoutospecifythemostused
headersinanemailmessage,theseare:
:subjectThesubjectofthemessage,ifthisisomitted,ActionMailerwillask
theRailsI18nclassforatranslated:subjectinthescopeof[mailer_scope,
action_name]orifthisismissing,willtranslatethehumanizedversionofthe
action_name
:toWhothemessageisdestinedfor,canbeastringofaddresses,oranarrayof
addresses.
:fromWhothemessageisfrom
:ccWhoyouwouldliketoCarbonCopyonthisemail,canbeastringof
addresses,oranarrayofaddresses.
:bccWhoyouwouldliketoBlindCarbonCopyonthisemail,canbeastring
ofaddresses,oranarrayofaddresses.
:reply_toWhotosettheReplyToheaderoftheemailto.
:dateThedatetosaytheemailwassenton.
Youcansetdefaultvaluesforanyoftheaboveheaders(except:date)byusingthe
defaultclassmethod
>>ThegeneratedmodelinheritsfromActionMailer::Base
>>smtp_settings
Allowsdetailedconfigurationfor:smtpdeliverymethod:
:addressAllowsyoutousearemotemailserver.Justchangeitfromitsdefault
"localhost"setting.
:portOntheoffchancethatyourmailserverdoesn'trunonport25,youcan

changeit.
:domainIfyouneedtospecifyaHELOdomain,youcandoithere.
:user_nameIfyourmailserverrequiresauthentication,settheusernameinthis
setting.
:passwordIfyourmailserverrequiresauthentication,setthepasswordinthis
setting.
:authenticationIfyourmailserverrequiresauthentication,youneedtospecify
theauthenticationtypehere.Thisisasymbolandoneof:plain,:login,
:cram_md5.
:enable_starttls_autoSetthistofalseifthereisaproblemwithyourserver
certificatethatyoucannotresolve.

You might also like