Skip to content

Instantly share code, notes, and snippets.

@amicojeko
Last active November 15, 2022 14:15
Show Gist options
  • Save amicojeko/3c1680ba5c942f6e5dc9b785c1033d02 to your computer and use it in GitHub Desktop.
Save amicojeko/3c1680ba5c942f6e5dc9b785c1033d02 to your computer and use it in GitHub Desktop.
Secret Santa's Helper Bot
# frozen_string_literal: true
# To obtain a google mail's password, you need to:
# 1. Go to gmail
# 2. in the top right corner click on the menu icon and select 'Account'
# 3. Click on 'Sign in & Security'
# 4. Scroll down the 'Security' and find a section called 'Signing in to Google'.
# 5. Click on "App passwords"
# 6. You should see a dropdown labelled 'Select App'. Select Mail.
# 7. For the 'on my device' dropdown select 'Other' and type in commandline or whatever you want to call the app.
# 8. Click 'Generate'. A password will be generated. Copy that password and replace the password you were using in your options hash with the generated password:
require 'mail'
SENDER = "Secret Santa's Helper Bot <jekolino@gmail.com>"
PARTICIPANTS = [
{ email: "recipient_1@recipient.com", first_name: "Name", last_name: "Surname", address: "123, Address street, ZIP, City, Country" },
{ email: "recipient_2@recipient.com", first_name: "Name", last_name: "Surname", address: "123, Address street, ZIP, City, Country" },
{ email: "recipient_3@recipient.com", first_name: "Name", last_name: "Surname", address: "123, Address street, ZIP, City, Country" },
].shuffle.freeze
MAIL_OPTIONS = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => 'email@gmail.com',
:password => 'password',
:authentication => 'plain',
:enable_starttls_auto => true
}.freeze
Mail.defaults do
delivery_method :smtp, MAIL_OPTIONS
end
PARTICIPANTS.each_with_index do |participant, i|
recipient = PARTICIPANTS[i + 1] || PARTICIPANTS[0]
Mail.deliver do
to participant[:email]
from SENDER
subject "Ciao #{participant[:first_name]}! tu sarai il Secret Santa di..."
body "
Ciao #{participant[:first_name]}!\n
Tu sarai il Secret Santa di #{recipient[:first_name]} #{recipient[:last_name]}!\n
\n
Il suo indirizzo e':\n
#{recipient[:address]}\n
\n
Buon Natale!\n
\n
P.S. Questo e' un messaggio automatico, io (Jeko) non so chi sia il tuo Secret Santa, e' un segreto!\n
il codice di questo bot e' open source, puoi vederlo qui: https://gist.github.com/amicojeko/3c1680ba5c942f6e5dc9b785c1033d02"
end
end
@fabn
Copy link

fabn commented Nov 14, 2022

Mancano i test πŸ˜‰

@amicojeko
Copy link
Author

Mancano i test πŸ˜‰

πŸ˜‚πŸ˜‚πŸ˜‚πŸ€·β€β™‚οΈ

@mdesantis
Copy link

Mancano i test wink

πŸ˜‚

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment