SlideShare a Scribd company logo
1 of 7
Action Mailer  Action Mailer is the Rails component that enables applications to send and receive e-mail. In this chapter we will see how to send an email using Rails. So lets start with creating a emails project using following command. C:ubyamp;gt; rails emails This will create required framework to proceed. Now we will start with configuring Action Mailer. Action Mailer - Configuration Following are the steps you have to follow to complete your configuration before proceeding with actual work: Go into config folder of your emails project and open environment.rb file and add the following line at the bottom of this file. ActionMailer::Base.delivery_method = :smtp
This tells ActionMailer that you want to user SMTP server. You can also set it to be :sendmail if you are using a Unix-based operating system such as Mac OS X or Linux. Add the following lines of code to the bottom of your environment.rb as well. ActionMailer::Base.server_settings = {    :address => "smtp.site.com",    :port => 25,    :domain => “site.com",    :authentication => :login,    :user_name => "username",    :password => "password", } Replace each hash value with proper settings for your Simple Mail Transfer Protocol (SMTP) server. You can take this information from your Internet Service Provider if you already don't know. You don't need to change port number 25 and authentication type if you are using standard SMTP server. You may also change the default email message format. If you prefer to send email in HTML instead of plain text format, add the following line to config/environment.rb as well:
ActionMailer::Base.default_content_type = "text/html" ActionMailer::Base.default_content_type could be set to "text/plain", "text/html", and "text/enriched". The default value is "text/plain". Next step will be to create a mailer Generate a mailer: Use the following command to generate a mailer as follows: C:ubyamp;gt; cd emails C:ubymails> ruby script/generate mailer Emailer This will create a file emailer.rb in appodels directory. Check the content of this file is as follows:
class Emailer < ActionMailer::Base end Let's create one method as follows. class Emailer < ActionMailer::Base    def contact(recipient, subject, message, sent_at = Time.now)       @subject = subject       @recipients = recipient       @from = 'no-reply@yourdomain.com'       @sent_on = sent_at 	  @body["title"] = 'This is title'   	  @body["email"] = 'sender@yourdomain.com'    	  @body["message"] = message end end The contact method has four parameters a recipient, subject, message and a sent_at, which defines when the e-mail is sent. The method also defines six standard parameters that are a part of every ActionMailer method:
[object Object]
 @body is a Ruby hash that contains values with which you can populate the mail template. You created three key-value pairs: title, email, and message
 @recipients is a list of the people to whom the message is being sent.

More Related Content

What's hot

Day3_Part 2_Apache_JMeter_Config_Elements
Day3_Part 2_Apache_JMeter_Config_ElementsDay3_Part 2_Apache_JMeter_Config_Elements
Day3_Part 2_Apache_JMeter_Config_ElementsSravanthi N
 
1and1Mail Advanced Features - Auto IP Switcher
1and1Mail Advanced Features - Auto IP Switcher1and1Mail Advanced Features - Auto IP Switcher
1and1Mail Advanced Features - Auto IP SwitcherYeteSoft
 
Sending mail in mule
Sending mail in muleSending mail in mule
Sending mail in muleSon Nguyen
 
Inbound Email Troubleshooting Guide
Inbound Email Troubleshooting GuideInbound Email Troubleshooting Guide
Inbound Email Troubleshooting Guideguestc1eed9
 
1and1Mail Advanced Features - Auto Remove Bounced and Unsubscribed
 1and1Mail Advanced Features - Auto Remove Bounced and Unsubscribed 1and1Mail Advanced Features - Auto Remove Bounced and Unsubscribed
1and1Mail Advanced Features - Auto Remove Bounced and UnsubscribedYeteSoft
 
1and1Mail Quickstart Guide - View Reports
1and1Mail Quickstart Guide - View Reports1and1Mail Quickstart Guide - View Reports
1and1Mail Quickstart Guide - View ReportsYeteSoft
 
1and1Mail Quickstart Guide - SMTP Account Setup
1and1Mail Quickstart Guide - SMTP Account Setup1and1Mail Quickstart Guide - SMTP Account Setup
1and1Mail Quickstart Guide - SMTP Account SetupYeteSoft
 
Input and output flow using file to string and logger component
Input and output flow using file to string and logger componentInput and output flow using file to string and logger component
Input and output flow using file to string and logger componentSon Nguyen
 
MarvelSoft email hosting guide
MarvelSoft email hosting guideMarvelSoft email hosting guide
MarvelSoft email hosting guideRanganath Shivaram
 
Setting emails on android
Setting emails on androidSetting emails on android
Setting emails on androidWasim Ismail
 
JSP diana y yo
JSP diana y yoJSP diana y yo
JSP diana y yomichael
 
Login With External Accounts In Odoo
Login With External Accounts In OdooLogin With External Accounts In Odoo
Login With External Accounts In OdooAnisha Technaureus
 
Winter '19 release development.ppt
Winter '19 release development.pptWinter '19 release development.ppt
Winter '19 release development.pptKailas Shimpi
 

What's hot (16)

Day3_Part 2_Apache_JMeter_Config_Elements
Day3_Part 2_Apache_JMeter_Config_ElementsDay3_Part 2_Apache_JMeter_Config_Elements
Day3_Part 2_Apache_JMeter_Config_Elements
 
1and1Mail Advanced Features - Auto IP Switcher
1and1Mail Advanced Features - Auto IP Switcher1and1Mail Advanced Features - Auto IP Switcher
1and1Mail Advanced Features - Auto IP Switcher
 
Messaging APIs of RingCentral
Messaging APIs of RingCentralMessaging APIs of RingCentral
Messaging APIs of RingCentral
 
Sending mail in mule
Sending mail in muleSending mail in mule
Sending mail in mule
 
Inbound Email Troubleshooting Guide
Inbound Email Troubleshooting GuideInbound Email Troubleshooting Guide
Inbound Email Troubleshooting Guide
 
1and1Mail Advanced Features - Auto Remove Bounced and Unsubscribed
 1and1Mail Advanced Features - Auto Remove Bounced and Unsubscribed 1and1Mail Advanced Features - Auto Remove Bounced and Unsubscribed
1and1Mail Advanced Features - Auto Remove Bounced and Unsubscribed
 
1and1Mail Quickstart Guide - View Reports
1and1Mail Quickstart Guide - View Reports1and1Mail Quickstart Guide - View Reports
1and1Mail Quickstart Guide - View Reports
 
1and1Mail Quickstart Guide - SMTP Account Setup
1and1Mail Quickstart Guide - SMTP Account Setup1and1Mail Quickstart Guide - SMTP Account Setup
1and1Mail Quickstart Guide - SMTP Account Setup
 
Input and output flow using file to string and logger component
Input and output flow using file to string and logger componentInput and output flow using file to string and logger component
Input and output flow using file to string and logger component
 
Ssi
SsiSsi
Ssi
 
Bloom links
Bloom linksBloom links
Bloom links
 
MarvelSoft email hosting guide
MarvelSoft email hosting guideMarvelSoft email hosting guide
MarvelSoft email hosting guide
 
Setting emails on android
Setting emails on androidSetting emails on android
Setting emails on android
 
JSP diana y yo
JSP diana y yoJSP diana y yo
JSP diana y yo
 
Login With External Accounts In Odoo
Login With External Accounts In OdooLogin With External Accounts In Odoo
Login With External Accounts In Odoo
 
Winter '19 release development.ppt
Winter '19 release development.pptWinter '19 release development.ppt
Winter '19 release development.ppt
 

Similar to Action Mailer

Laravel mail example how to send an email using markdown template in laravel 8
Laravel mail example how to send an email using markdown template in laravel 8Laravel mail example how to send an email using markdown template in laravel 8
Laravel mail example how to send an email using markdown template in laravel 8Katy Slemon
 
Setting up your own email server with hmailserver
Setting up your own email server with hmailserverSetting up your own email server with hmailserver
Setting up your own email server with hmailserverrifqirr
 
Working with data.pptx
Working with data.pptxWorking with data.pptx
Working with data.pptxSherinRappai
 
Task scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorialTask scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorialKaty Slemon
 
Php forms and validations by naveen kumar veligeti
Php forms and validations by naveen kumar veligetiPhp forms and validations by naveen kumar veligeti
Php forms and validations by naveen kumar veligetiNaveen Kumar Veligeti
 
Article marketing robot_instructions_how_to
Article marketing robot_instructions_how_toArticle marketing robot_instructions_how_to
Article marketing robot_instructions_how_totimegates
 
Php Mysql Feedrss
Php Mysql FeedrssPhp Mysql Feedrss
Php Mysql FeedrssRCS&RDS
 
Install iRedMail on Red Hat Enterprise Linux, CentOS
Install iRedMail on Red Hat Enterprise Linux, CentOSInstall iRedMail on Red Hat Enterprise Linux, CentOS
Install iRedMail on Red Hat Enterprise Linux, CentOSInfoExcavator
 
Install iRedMail on Red Hat Enterprise Linux, CentOS
Install iRedMail on Red Hat Enterprise Linux, CentOSInstall iRedMail on Red Hat Enterprise Linux, CentOS
Install iRedMail on Red Hat Enterprise Linux, CentOSMd Meherab Hossen
 
Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP yucefmerhi
 
How to simplify Email oriented workflow with - Visendo SMTP Extender
How to simplify Email oriented workflow with - Visendo SMTP Extender How to simplify Email oriented workflow with - Visendo SMTP Extender
How to simplify Email oriented workflow with - Visendo SMTP Extender Johannes Cosmin dumitru
 
Validate Email with JavaScript.pdf
Validate Email with JavaScript.pdfValidate Email with JavaScript.pdf
Validate Email with JavaScript.pdfEmailConcern
 
Email Router Configuration - Gmail and microsoft dynamics crm 2016 online int...
Email Router Configuration - Gmail and microsoft dynamics crm 2016 online int...Email Router Configuration - Gmail and microsoft dynamics crm 2016 online int...
Email Router Configuration - Gmail and microsoft dynamics crm 2016 online int...Naveen Kumar
 

Similar to Action Mailer (20)

Ruby
RubyRuby
Ruby
 
Laravel mail example how to send an email using markdown template in laravel 8
Laravel mail example how to send an email using markdown template in laravel 8Laravel mail example how to send an email using markdown template in laravel 8
Laravel mail example how to send an email using markdown template in laravel 8
 
Lecture19
Lecture19Lecture19
Lecture19
 
Send Email In Asp.Net
Send Email In Asp.NetSend Email In Asp.Net
Send Email In Asp.Net
 
Send email
Send emailSend email
Send email
 
Setting up your own email server with hmailserver
Setting up your own email server with hmailserverSetting up your own email server with hmailserver
Setting up your own email server with hmailserver
 
Working with data.pptx
Working with data.pptxWorking with data.pptx
Working with data.pptx
 
Lecture19
Lecture19Lecture19
Lecture19
 
Task scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorialTask scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorial
 
Php forms and validations by naveen kumar veligeti
Php forms and validations by naveen kumar veligetiPhp forms and validations by naveen kumar veligeti
Php forms and validations by naveen kumar veligeti
 
AWS SES
AWS SESAWS SES
AWS SES
 
Article marketing robot_instructions_how_to
Article marketing robot_instructions_how_toArticle marketing robot_instructions_how_to
Article marketing robot_instructions_how_to
 
Php Mysql Feedrss
Php Mysql FeedrssPhp Mysql Feedrss
Php Mysql Feedrss
 
Install iRedMail on Red Hat Enterprise Linux, CentOS
Install iRedMail on Red Hat Enterprise Linux, CentOSInstall iRedMail on Red Hat Enterprise Linux, CentOS
Install iRedMail on Red Hat Enterprise Linux, CentOS
 
Install iRedMail on Red Hat Enterprise Linux, CentOS
Install iRedMail on Red Hat Enterprise Linux, CentOSInstall iRedMail on Red Hat Enterprise Linux, CentOS
Install iRedMail on Red Hat Enterprise Linux, CentOS
 
Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP
 
How to simplify Email oriented workflow with - Visendo SMTP Extender
How to simplify Email oriented workflow with - Visendo SMTP Extender How to simplify Email oriented workflow with - Visendo SMTP Extender
How to simplify Email oriented workflow with - Visendo SMTP Extender
 
Validate Email with JavaScript.pdf
Validate Email with JavaScript.pdfValidate Email with JavaScript.pdf
Validate Email with JavaScript.pdf
 
Email Router Configuration - Gmail and microsoft dynamics crm 2016 online int...
Email Router Configuration - Gmail and microsoft dynamics crm 2016 online int...Email Router Configuration - Gmail and microsoft dynamics crm 2016 online int...
Email Router Configuration - Gmail and microsoft dynamics crm 2016 online int...
 
Merb
MerbMerb
Merb
 

More from SHC

Perform brute force
Perform brute forcePerform brute force
Perform brute forceSHC
 
AJAX ASP.Net
AJAX ASP.NetAJAX ASP.Net
AJAX ASP.NetSHC
 
C++ plus data structures, 3rd edition (2003)
C++ plus data structures, 3rd edition (2003)C++ plus data structures, 3rd edition (2003)
C++ plus data structures, 3rd edition (2003)SHC
 
Inside Asp.Net Web Matrix
Inside Asp.Net Web MatrixInside Asp.Net Web Matrix
Inside Asp.Net Web MatrixSHC
 
V Pro Bp08505 Phase Iii Edited
V Pro Bp08505 Phase Iii EditedV Pro Bp08505 Phase Iii Edited
V Pro Bp08505 Phase Iii EditedSHC
 
V Pro Bp08505 Phase Iii Edited
V Pro Bp08505 Phase Iii EditedV Pro Bp08505 Phase Iii Edited
V Pro Bp08505 Phase Iii EditedSHC
 
V Pro Bp08505 Phase Ii Edited
V Pro Bp08505 Phase Ii EditedV Pro Bp08505 Phase Ii Edited
V Pro Bp08505 Phase Ii EditedSHC
 
Intel® V Pro™ Technology
Intel® V Pro™ TechnologyIntel® V Pro™ Technology
Intel® V Pro™ TechnologySHC
 
XForms with Linux
XForms with LinuxXForms with Linux
XForms with LinuxSHC
 
XForms
XFormsXForms
XFormsSHC
 
Rails
RailsRails
RailsSHC
 
Call
CallCall
CallSHC
 
Ruby Security
Ruby SecurityRuby Security
Ruby SecuritySHC
 
Web Services
Web ServicesWeb Services
Web ServicesSHC
 
Pragmatic Agile Web Development With Rails.3rd Edition.2009
Pragmatic   Agile Web Development With Rails.3rd Edition.2009Pragmatic   Agile Web Development With Rails.3rd Edition.2009
Pragmatic Agile Web Development With Rails.3rd Edition.2009SHC
 
Ruby Basics
Ruby BasicsRuby Basics
Ruby BasicsSHC
 
Ruby Installation
Ruby InstallationRuby Installation
Ruby InstallationSHC
 
Mysql Statments
Mysql StatmentsMysql Statments
Mysql StatmentsSHC
 
Mysql Fun
Mysql FunMysql Fun
Mysql FunSHC
 
Mysql
MysqlMysql
MysqlSHC
 

More from SHC (20)

Perform brute force
Perform brute forcePerform brute force
Perform brute force
 
AJAX ASP.Net
AJAX ASP.NetAJAX ASP.Net
AJAX ASP.Net
 
C++ plus data structures, 3rd edition (2003)
C++ plus data structures, 3rd edition (2003)C++ plus data structures, 3rd edition (2003)
C++ plus data structures, 3rd edition (2003)
 
Inside Asp.Net Web Matrix
Inside Asp.Net Web MatrixInside Asp.Net Web Matrix
Inside Asp.Net Web Matrix
 
V Pro Bp08505 Phase Iii Edited
V Pro Bp08505 Phase Iii EditedV Pro Bp08505 Phase Iii Edited
V Pro Bp08505 Phase Iii Edited
 
V Pro Bp08505 Phase Iii Edited
V Pro Bp08505 Phase Iii EditedV Pro Bp08505 Phase Iii Edited
V Pro Bp08505 Phase Iii Edited
 
V Pro Bp08505 Phase Ii Edited
V Pro Bp08505 Phase Ii EditedV Pro Bp08505 Phase Ii Edited
V Pro Bp08505 Phase Ii Edited
 
Intel® V Pro™ Technology
Intel® V Pro™ TechnologyIntel® V Pro™ Technology
Intel® V Pro™ Technology
 
XForms with Linux
XForms with LinuxXForms with Linux
XForms with Linux
 
XForms
XFormsXForms
XForms
 
Rails
RailsRails
Rails
 
Call
CallCall
Call
 
Ruby Security
Ruby SecurityRuby Security
Ruby Security
 
Web Services
Web ServicesWeb Services
Web Services
 
Pragmatic Agile Web Development With Rails.3rd Edition.2009
Pragmatic   Agile Web Development With Rails.3rd Edition.2009Pragmatic   Agile Web Development With Rails.3rd Edition.2009
Pragmatic Agile Web Development With Rails.3rd Edition.2009
 
Ruby Basics
Ruby BasicsRuby Basics
Ruby Basics
 
Ruby Installation
Ruby InstallationRuby Installation
Ruby Installation
 
Mysql Statments
Mysql StatmentsMysql Statments
Mysql Statments
 
Mysql Fun
Mysql FunMysql Fun
Mysql Fun
 
Mysql
MysqlMysql
Mysql
 

Recently uploaded

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

Action Mailer

  • 1. Action Mailer Action Mailer is the Rails component that enables applications to send and receive e-mail. In this chapter we will see how to send an email using Rails. So lets start with creating a emails project using following command. C:ubyamp;gt; rails emails This will create required framework to proceed. Now we will start with configuring Action Mailer. Action Mailer - Configuration Following are the steps you have to follow to complete your configuration before proceeding with actual work: Go into config folder of your emails project and open environment.rb file and add the following line at the bottom of this file. ActionMailer::Base.delivery_method = :smtp
  • 2. This tells ActionMailer that you want to user SMTP server. You can also set it to be :sendmail if you are using a Unix-based operating system such as Mac OS X or Linux. Add the following lines of code to the bottom of your environment.rb as well. ActionMailer::Base.server_settings = { :address => "smtp.site.com", :port => 25, :domain => “site.com", :authentication => :login, :user_name => "username", :password => "password", } Replace each hash value with proper settings for your Simple Mail Transfer Protocol (SMTP) server. You can take this information from your Internet Service Provider if you already don't know. You don't need to change port number 25 and authentication type if you are using standard SMTP server. You may also change the default email message format. If you prefer to send email in HTML instead of plain text format, add the following line to config/environment.rb as well:
  • 3. ActionMailer::Base.default_content_type = "text/html" ActionMailer::Base.default_content_type could be set to "text/plain", "text/html", and "text/enriched". The default value is "text/plain". Next step will be to create a mailer Generate a mailer: Use the following command to generate a mailer as follows: C:ubyamp;gt; cd emails C:ubymails> ruby script/generate mailer Emailer This will create a file emailer.rb in appodels directory. Check the content of this file is as follows:
  • 4. class Emailer < ActionMailer::Base end Let's create one method as follows. class Emailer < ActionMailer::Base def contact(recipient, subject, message, sent_at = Time.now) @subject = subject @recipients = recipient @from = 'no-reply@yourdomain.com' @sent_on = sent_at @body["title"] = 'This is title' @body["email"] = 'sender@yourdomain.com' @body["message"] = message end end The contact method has four parameters a recipient, subject, message and a sent_at, which defines when the e-mail is sent. The method also defines six standard parameters that are a part of every ActionMailer method:
  • 5.
  • 6. @body is a Ruby hash that contains values with which you can populate the mail template. You created three key-value pairs: title, email, and message
  • 7. @recipients is a list of the people to whom the message is being sent.
  • 8. @from defines who the e-mail is from.
  • 9.
  • 10. Now let's define our view in appiewsmailsndex.rhtml <h1>Send Email</h1> <%= start_form_tag :action => 'sendmail' %> <p><label for="email_subject">Subject</label>: <%= text_field 'email', 'subject' %></p> <p><label for="email_recipient">Recipient</label>: <%= text_field 'email', 'recipient' %></p> <p><label for="email_message">Message</label><br/> <%= text_area 'email', 'message' %></p> <%= submit_tag "Send" %> <%= end_form_tag %>