-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsendmail.rb
36 lines (31 loc) · 1014 Bytes
/
sendmail.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
require "net/smtp"
# params :
# ARGV[0] = subject
# ARGV[1] = content
# ARGV[2] = filename
# ARGV[3] = to
def sendemail(subject,content,to=nil)
sendmessage = "Subject: "+subject +"\n\n"+content
smtp = Net::SMTP.start("mail.xj.cninfo.net",25,"mail.xj.cninfo.net",'saq','wei720503',:login)
smtp.send_message sendmessage,from,to
smtp.finish
end
def sendemail_file(subject,filename,to)
content = ""
File.open(filename) do |file|
file.each_line {|line| content += "#{line}\n" }
end
sendemail(subject,content,to)
end
subject = ARGV[0] || "system autoly send"
content = ARGV[1] || ""
filename = ARGV[2] || ""
to = ARGV[3]
if content.to_s == "" and filename.to_s!=""
sendemail_file(subject,filename,to)
else
content = "Nothing" if content.to_s == ""
sendemail(subject,content,to)
end