class MediTAF::Utils::Email::Mail
Attributes
gmail[R]
Public Class Methods
new(username, options = {})
click to toggle source
# File lib/MediTAF/utils/mail.rb, line 11 def initialize(username, options = {}) @gmail = Gmail.new(username, options) end
Public Instance Methods
delete(from, subject=nil, date=Time.now)
click to toggle source
finds and deletes the email @param from [String] the from email address. @param subject [String] the subject of the email. @param date [String] the date of the email. Defaults to today's date.
# File lib/MediTAF/utils/mail.rb, line 39 def delete(from, subject=nil, date=Time.now) raise SubjectNil if subject.nil? @gmail.inbox.find(:all, on: Date.parse("#{date}"), from: "#{from}", subject: subject).each do |email| email.delete! end end
find_email(from, subject=nil, newest=true, date=Time.now, to=nil)
click to toggle source
finds the unread invite email from iMedidata @param from [String] the from email address. @param subject [String] the subject of the email. @param newest [Boolean] the subject of the email. @param date [String] the date of the email. Defaults to today's date. @param to [String] the recepient email address.
# File lib/MediTAF/utils/mail.rb, line 21 def find_email(from, subject=nil, newest=true, date=Time.now, to=nil) email_options={} email_options[:from]= "#{from}" if from email_options[:to]= "#{to}" if to email_options[:on]= Date.parse("#{date}") if date Message.new do @gmail.inbox.find(:unread,email_options).each do |email| subject.nil? || email.message.subject == subject end.send(newest ? :last : :first) end end
logged_in?()
click to toggle source
whether or not you are logged in
# File lib/MediTAF/utils/mail.rb, line 52 def logged_in? @gmail.logged_in? end
logout()
click to toggle source
logs out of Mail
# File lib/MediTAF/utils/mail.rb, line 47 def logout @gmail.logout end
send_mail(addr, title, contents)
click to toggle source
sends mail using configured email address @param addr [String] the address to send to @param title [String] the subject of the email @param contents [String] the glob of the email
# File lib/MediTAF/utils/mail.rb, line 60 def send_mail(addr, title, contents) if logged_in? @gmail.deliver do to addr subject title html_part do content_type 'text/html; charset=UTF-8' body contents end delivery_method :smtp, {address: 'smtp.lab1.hdc.mdsol.com', port: 80} if `hostname` =~ /hdc505lb/ end end end