Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 21, 2021 11:48 am GMT

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

Easy Ruby

Table of contents


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:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To