class Mail::SMTPConnection

Sending Email with SMTP ↑

Mail allows you to send emails using an open SMTP connection. This is done by passing a created Net::SMTP object. This way we can get better performance to our local mail server by reducing the number of connections at any one time.

Sending via SMTP server on Localhost ↑

To send mail open a connection with Net::Smtp using any options you like

Delivering the email ↑

Once you have the settings right, sending the email is done by:

smtp_conn = Net::SMTP.start(settings[:address], settings[:port])
Mail.defaults do
  delivery_method :smtp_connection, { :connection => smtp_conn }
end

Mail.deliver do
  to 'mikel@test.lindsaar.net'
  from 'ada@test.lindsaar.net'
  subject 'testing sendmail'
  body 'testing sendmail'
end

Or by calling deliver on a Mail message

mail = Mail.new do
  to 'mikel@test.lindsaar.net'
  from 'ada@test.lindsaar.net'
  subject 'testing sendmail'
  body 'testing sendmail'
end

mail.deliver!