require 'net/smtp' # メールサーバーの設定 smtp_server = '[MAIl_SERVER]' smtp_port = 587 # 送信元メールアドレスと認証情報 from_address = '[FROM_MAIL_ADDRESS]' password = '[PASSWORD]' # 送信先メールアドレス to_address = '[TO_MAIL_ADDRESS]' # 件名と本文 subject = 'Test Email' body = 'This is a test email from Ruby.' # メールヘッダ message = <<MESSAGE From: #{from_address} To: #{to_address} Subject: #{subject} Date: #{Time.now.strftime("%a, %d %b %Y %H:%M:%S %z")} # "Date" ヘッダーを追加 MIME-Version: 1.0 Content-type: text/html #{body} MESSAGE # SMTPセッションの確立 Net::SMTP.start(smtp_server, smtp_port, 'localhost', from_address, password, :plain) do |smtp| # メール送信 smtp.send_message(message, from_address, to_address) end puts 'Email sent successfully!'