Net::smtp carriage returns

I’m new to ruby and trying to build a script that logs into a cisco pix
and diff the config from the day before. I’m having issues passing the
diff to an email and having carriage returns after each change.
Basically it outputs all text with no carriage returns to the body.
Here is the code for the email side. Any help would be appreciated.

def sendMail
from = '[email protected]
to = ‘[email protected]
dif = Diffy::Diff.new("#{@a[0]}", “#{@a[1]}”, :source => ‘files’,
:diff => “-b”)
message = <<MESSAGE
From: “#{from}”
To: “#{to}”
MIME-Version: 1.0
Content-type: text/html
Subject: The firewall has changed

The firewall has changed since yesterday!!!
#{dif}
MESSAGE

Net::SMTP.start('mail.home.com',25) do |smtp|
    smtp.send_message message,from,to
end

end

Your problem has to do with the result of:

dif = Diffy::Diff.new("#{@a[0]}", “#{@a[1]}”, :source => ‘files’,
:diff => “-b”)

I’m not familiar with the Diffy (gem?)

you could test what is the state of the object dif by typing to the
console:


puts dif.to_s (or just dif)

Regards,

Eduardo

Eduardo B. wrote in post #1058518:

Your problem has to do with the result of:

dif = Diffy::Diff.new("#{@a[0]}", “#{@a[1]}”, :source => ‘files’,
:diff => “-b”)

I’m not familiar with the Diffy (gem?)

you could test what is the state of the object dif by typing to the
console:


puts dif.to_s (or just dif)

Regards,

Eduardo

I get the desired results from the puts dif. It creates a separate line
for the differences in the file.

I think I found an easier way to do this. I loaded the mail gem and
used this code. Everything seems to work now.

def sendMail

File.open(“diff.log”, “w”) do |d|
d.flock(File::LOCK_EX)
d.puts Diffy::Diff.new("#{@a[0]}", “#{@a[1]}”, :source => ‘files’,
:diff => “-b”)
d.flock(File::LOCK_UN)
end

mail = Mail.new do
from ‘[email protected]
to ‘[email protected]
subject ‘Firewall has changed since yesterday’
body File.read(‘diff.log’)
end

mail.deliver!

end

Thanks,
Tim