J'ai fait la même chose dans Ruby. Python3: envoyer des e-mails avec Starttls Je l'ai essayé sur hi-ho.ne.jp.
Installation de la bibliothèque
sudo gem install mail
hi-ho.rb
#! /usr/bin/ruby
# -*- encoding: utf-8 -*-
#
# hi-ho.rb
#
# Jul/08/2020
#
# ---------------------------------------------------------------------
require "mail"
require "dotenv"
STDERR.puts "***début***"
Dotenv.load
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 += "Bonjour.\n"
str_out += "Jul/08/2020\n"
str_out += "PM 15:58\n"
mail = Mail.new do
from from
to to
subject "Hello from Hi-ho PM 15:58"
content_type 'text/plain; charset=UTF-8'
body str_out
end
mail.delivery_method(:smtp,
address: server,
port: port,
authentication: :login,
us
er_name: usr,
password: password
)
mail.deliver
STDERR.puts "***Fin***"
# ---------------------------------------------------------------------
.env
SERVER = 'hi-ho.mose-mail.jp'
PORT = 587
USR = '****@hi-ho.ne.jp'
PASSWORD = '****'
FROM = '****@hi-ho.ne.jp'
TO = '[email protected]'
Résultat d'exécution
$ ./hi-ho.rb
***début***
hi-ho.mose-mail.jp
587
***Fin***
Je l'ai confirmé dans la prochaine version.
$ ruby --version
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]
Recommended Posts