On Jan 15, 2008, at 12:54 PM, Peter B. wrote:
The e-mail server here at my company is Lotus Notes. I’ve used it for
years as an SMTP server.
Thanks,
Peter
Posted via http://www.ruby-forum.com/.
require “net/smtp”
class Email
class Error < ::StandardError; end
USER = ENV[“USER”] || ENV[“USERNAME”] || ENV[“LOGNAME”]
attr_accessor “user”
attr_accessor “from”
attr_accessor “to”
attr_accessor “subject”
attr_accessor “message”
attr_accessor “sent”
alias_method “sent?”, “sent”
def initialize *a, &b
options, messages = a.partition{|x| Hash === x}
opts = options.inject({}){|h,o| h.update o}
@user = opts[“user”] || opts[:user] || USER
@to = opts[“to”] || opts[:to] || “#{ @user }@localhost.localdomain”
@from = opts[“from”] || opts[:from] || “#{ @user }
@localhost.localdomain”
@subject = opts[“subject”] || opts[:subject] || “[RUBY EMAIL]”
@sent = false
@message =
if messages.empty?
opts[“message”] || opts[:message]
else
messages.join
end
@message = b.call(self) if b
email if @message
end
def email
raise Error, “already sent!” if @sent
msg = “To: %s\nFrom: %s\nSubject: %s\n\n%s” % [@to, @from,
@subject, @message]
Net::SMTP.start(“localhost”){|smtp| smtp.send_message msg, @to,
@from }
@sent = true
self
end
alias_method “email!”, “email”
end
EMail = Email
def EMail *a, &b
EMail::new *a, &b
end
def Email *a, &b
Email::new *a, &b
end
def email *a, &b
Email::new *a, &b
end
if $0 == FILE
p(EMail(“test 1 @ #{ Time::now }”, “to” =>
“[email protected]”, “from” => “[email protected]”))
p(EMail(“to” => “[email protected]”, “from” =>
“[email protected]”){ “test 2 @ #{ Time::now }” })
p(EMail(“to” => “[email protected]”){ “test 3 @ #
{ Time::now }” })
end
a @ http://codeforpeople.com/