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 info options = { address: 'smtp.gmail.com', port: 587, # gmail smtp port number domain: 'gmail.com', user_name: 'youremail@gmail.com', password: 'yourpassword', authentication: 'plain' }
- Initialize Mail
delivery_method
info:
Mail.defaults do delivery_method :smtp, options end
- Send email 📧 :
Mail.deliver do to 'myfriend@yopmail.com' from 'youremail@gmail.com' subject 'Sending email using Ruby' body 'Easy peasy lemon squeezy' end
Here the final code:
require 'mail' # Gmail account info options = { address: 'smtp.gmail.com', port: 587, domain: 'gmail.com', user_name: 'youremail@gmail.com', password: 'yourpassword', authentication: 'plain' } Mail.defaults do delivery_method :smtp, options end Mail.deliver do to 'myfriend@yopmail.com' from 'youremail@gmail.com' subject 'Sending email using Ruby' body 'Easy peasy lemon squeezy' end puts 'Email sent'
The ease of Ruby 💎
Table of contents
- Javascript 🚀 - Part 1
- Ruby 💎 - Part 2
- Python 🐍 - Part 3
Top comments (0)