To use Gmail SMTP to send emails in Ruby, you can use the following steps:
Install the gem 'mail' by running the following command in your terminal:
gem install mail
Create a new Ruby file and require the 'mail' gem:
require 'mail'
Set up your Gmail account credentials:
options = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => "your_username@gmail.com",
:password => "your_password",
:authentication => "plain",
:enable_starttls_auto => true
}
Use the 'mail' gem to create a new email:
Mail.defaults do
delivery_method :smtp, options
end
email = Mail.new do
from 'your_username@gmail.com'
to 'recipient@example.com'
subject 'This is a test email'
body 'Hello World!'
end
Send the email using the 'deliver' method:
email.deliver
And that's it! Your code should be able to send an email using Gmail SMTP.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-04 05:24:03 +0000
Seen: 18 times
Last updated: Jun 04 '23
What is the process for installing SASS/Compass in the DDEV web container?
On a remote host, the cursor control and Enter key in Rubymine do not function properly.
How does async execution relate to ruby-odbc?
What is the method of utilizing Ruby to add colored text to the terminal output?
Which languages are appropriate to use for a contemporary website?
How can an HTML form and a MySQL database be updated by several users simultaneously?
What is the process of generating swagger definitions using AWS SDKs?