Skip to content

Instantly share code, notes, and snippets.

@rickhull
Created August 26, 2010 19:12
Show Gist options
  • Select an option

  • Save rickhull/552019 to your computer and use it in GitHub Desktop.

Select an option

Save rickhull/552019 to your computer and use it in GitHub Desktop.
class MySMTP
HOST = 'mail.x.com'
PORT = 25
HELO = 'x.com'
def self.compose_mail(recipients, from, subject, body)
recipients = [recipients] if !recipients.kind_of?(Array)
["From: <#{from}>",
"To: " + recipients.map { |r| "<#{r}>" }.join(', '),
"Subject: #{subject}",
].join("\n") << "\n\n" << body << "\n"
end
def self.smtp_full(recipients, from, subject, body)
recipients = [recipients] if !recipients.kind_of?(Array)
Net::SMTP.start(HOST, PORT, HELO) { |agent|
agent.send_message(compose_mail(recipients, from, subject, body),
from, recipients)
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment