Sending emails automatically on a Mac

0

Macs come with Ruby and gmail is pretty ubiquitous. Here's how to send emails automatically at any time in the future using the two.

1. Create a text file called email.rb
require 'mail'

options = {
  address:              'smtp.gmail.net',
  port:                  587,
  domain:               'example.com',
  user_name:            'user@gmail.com',
  password:             'password',
  authentication:       'plain',
  enable_starttls_auto:  true
}

Mail.defaults do
  delivery_method :smtp, options
end            

mail = Mail.new do
  from    'user@gmail.com'
  to      'recipient@address.com'
  subject 'This is a test email'
end

mail.deliver!
2. Enable Less secure apps

Go to https://myaccount.google.com/lesssecureapps

3. Send email

Open Terminal and type ruby email.rb

5. If you don't want to enable Less secure apps on step (2)
require 'mail'

options = {
  address:              'smtp.sendgrid.net',
  port:                  587,
  domain:               'gmail.com',
  user_name:            'sendgrid-username',
  password:             'sendgrid-password',
  authentication:       'plain',
  enable_starttls_auto:  true
}

Mail.defaults do
  delivery_method :smtp, options
end            

mail = Mail.new do
  from    'user@gmail.com'
  to      'recipient@address.com'
  subject 'This is a test email using sendgrid'
end

mail.deliver!
5. Use atrun to schedule your email

See subtopic

  • 0 posts
  • 1 subtopic
  • 6 months ago by vince