Skip to content

Instantly share code, notes, and snippets.

@xmpf
Created December 9, 2021 08:28
Show Gist options
  • Save xmpf/74f72aa708d22a6af0be2f3dc9439d0e to your computer and use it in GitHub Desktop.
Save xmpf/74f72aa708d22a6af0be2f3dc9439d0e to your computer and use it in GitHub Desktop.
Send mail using Ruby on Rails
require "action_mailer"
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.server.com",
:port => 587,
:domain => "domain.com",
:authentication => :plain,
:user_name => "username",
:password => "password",
}
puts "[i] Sending messaage ..."
begin
ActionMailer::Base.mail(
from: "[email protected]",
to: "[email protected]",
subject: "test",
body: "test"
).deliver
rescue Net::SMTPAuthenticationError
puts "[-] Authentication error: Wrong credentials!"
exit 1
end
puts "[+] E-mail has been sent!"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment