Ruby: Send email with Starttls

I did the same thing in Ruby. Python3: Send mail with Starttls I tried it on

Library installation

sudo gem install mail


#! /usr/bin/ruby
# -*- encoding: utf-8 -*-
#	hi-ho.rb
#					Jul/08/2020
# ---------------------------------------------------------------------
require "mail"
require "dotenv"

STDERR.puts	"***start***"

server = ENV['SERVER']
port = ENV['PORT']
usr = ENV['USR']
password = ENV['PASSWORD']
from = ENV['FROM']
to = ENV['TO']
puts server
puts port

str_out = "Good Morning\n"
str_out += "Hello.\n"
str_out += "Jul/08/2020\n"
str_out += "PM 15:58\n"

mail = do
  from    from
  to      to
  subject "Hello from Hi-ho PM 15:58"
  content_type 'text/plain; charset=UTF-8'
  body    str_out

  address:        server,
  port:           port,
  authentication: :login,
er_name:      usr,
  password:       password


STDERR.puts	"***End***"
# ---------------------------------------------------------------------


PORT = 587
USR = '****'
PASSWORD = '****'
FROM = '****'
TO = '[email protected]'

Execution result

$ ./hi-ho.rb 

I confirmed it in the next version.

$ ruby --version
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]

Recommended Posts

Ruby: Send email with Starttls
Send an email from gmail with Ruby
Send email with spring boot
Getting Started with Ruby
Evolve Eevee with Ruby
Send an email with a PDF attachment via JavaMail
Ruby version switching with rbenv
I tried DI with Ruby
GraphQL Client starting with Ruby
Format Ruby with VS Code
Integer check method with ruby
I want to manually send an authorization email with Devise
[Ruby] problem with if statement
[Spring Boot] Send an email
Studying with CodeWar (ruby) ⑤ proc
Use Ruby with Google Colab
Getting Started with Ruby Modules
[ruby] Method call with argument
Install Ruby on MSYS2 with pacman
Ruby Scraping-Move Selenium Headless with VPS.
Learning Ruby with AtCoder 6 [Contest 168 Therefore]
Programming with ruby (on the way)
Studying with CodeWar (ruby) ④ case ~ when
[Ruby] Handle instance variables with instance methods
Handle DatePicker with Ruby / gtk3 + glade3
Impressions of making BlackJack-cli with Ruby
Install ruby on Ubuntu 20.04 with rbenv
Make a typing game with ruby