-
Notifications
You must be signed in to change notification settings - Fork 0
/
filemailer.rb
43 lines (34 loc) · 1.04 KB
/
filemailer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
['rubygems', 'action_mailer'].each { |w| require w }
ActionMailer::Base.delivery_method = :smtp
class MyMailer < ActionMailer::Base
def initialize(uname, psw)
ActionMailer::Base.smtp_settings = {
:tls => true,
:address => "smtp.uio.no",
:port => 587,
:domain => "uio.no",
:user_name => uname,
:password => psw,
:authentication => :login,
}
end
def botmail(to, sender, textfile, atm = false)
# strip any directory fluff from subject
subj = textfile.gsub(/.*\//,'').gsub(/\.\w*/,'')
#standard ActionMailer message setup
recipients to
from sender
subject subj
t = "";
File.open(textfile, 'r').each_line { |l| t += l }
body t
# set up attachment
# if atm
# aname = atm.gsub(/.*\//,'')
# attachments[aname] = File.read(atm)
# end
end
end
# Test
mailer = Mymailer.new('sjurher', 'P@$$word')
mailer.botmail('[email protected]','Sjur Hernes <[email protected]>','testtekst.txt').deliver