An Interest In:
Web News this Week
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
- March 26, 2024
June 21, 2021 11:48 am GMT
Original Link: https://dev.to/fralps/3-ways-to-send-emails-with-only-few-lines-of-code-and-gmail-ruby-part-2-23nc
3 ways to send emails with only few lines of code and Gmail - Ruby - Part 2
We will see how to send a simple email with the help of three different programming languages: Javascript, Ruby and Python
Before you start you need to create a Gmail account.
Do not forget to accept and allow the "Less secure apps" access in order use your scripts with your Gmail smtp connection.
I'll let you do this on your own, you don't need a tutorial for this
Ruby
- We are going to use the Mail gem:
gem install mail
- Require it at the beginning of your
send_email.rb
:
require 'mail'
- Declare Gmail account info:
# Gmail account infooptions = { address: 'smtp.gmail.com', port: 587, # gmail smtp port number domain: 'gmail.com', user_name: '[email protected]', password: 'yourpassword', authentication: 'plain'}
- Initialize Mail
delivery_method
info:
Mail.defaults do delivery_method :smtp, optionsend
- Send email :
Mail.deliver do to '[email protected]' from '[email protected]' subject 'Sending email using Ruby' body 'Easy peasy lemon squeezy'end
Here the final code:
require 'mail'# Gmail account infooptions = { address: 'smtp.gmail.com', port: 587, domain: 'gmail.com', user_name: '[email protected]', password: 'yourpassword', authentication: 'plain'}Mail.defaults do delivery_method :smtp, optionsendMail.deliver do to '[email protected]' from '[email protected]' subject 'Sending email using Ruby' body 'Easy peasy lemon squeezy'endputs 'Email sent'
The ease of Ruby
Table of contents
- Javascript - Part 1
- Ruby - Part 2
- Python - Part 3 - coming next week...
Original Link: https://dev.to/fralps/3-ways-to-send-emails-with-only-few-lines-of-code-and-gmail-ruby-part-2-23nc
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To