How to attach the filename in ruby. I have attach 1.txt as a file name .
The 1.txt
file has the following contents.
This is a test message.
But it doesn’t work for me.
require ‘net/smtp’
msgstr = <<END_OF_MESSAGE
From: FromAddress
To: ToAddress
Subject: test message
Message-Id: [email protected]
attachment: “1.txt”
END_OF_MESSAGE
smtp = Net::SMTP.start(“IpAdd” , portno)
smtp.send_message msgstr, 'fromAddress, ‘toAddress’
Vetrivel V. wrote:
How to attach the filename in ruby. I have attach 1.txt as a file name .
The 1.txt
file has the following contents.
This is a test message.
But it doesn’t work for me.
require ‘net/smtp’
msgstr = <<END_OF_MESSAGE
From: FromAddress
To: ToAddress
Subject: test message
Message-Id: [email protected]
attachment: “1.txt”
END_OF_MESSAGE
smtp = Net::SMTP.start(“IpAdd” , portno)
smtp.send_message msgstr, 'fromAddress, ‘toAddress’
I haven’t personally used this module but looking at the docs,
http://www.ruby-doc.org/stdlib/libdoc/net/smtp/rdoc/index.html I don’t
see an attachment option.
You could however do this. (untested)
mess_body= File.readlines(‘1.txt’)
msgstr = <<END_OF_MESSAGE
From: FromAddress
To: ToAddress
Subject: test message
Message-Id: [email protected]
#{mess_body}
END_OF_MESSAGE
(did I win that 10,000 pound UK lotto yet?)
I would suggest looking at the MailFactory gem (
http://rubyforge.org/projects/mailfactory/). It has a simple way to
construct the mail message, with attachments, that you can then send
using
net/smtp.
Damjan R. wrote:
Scott Lillibridge wrote:
I would suggest looking at the MailFactory gem (
http://rubyforge.org/projects/mailfactory/). It has a simple way to
construct the mail message, with attachments, that you can then send
using
net/smtp.
You can also try with Ruport:
r = Ruport::Report.new
r.add_mailer :default,
:host => “my.smtp.host”,
:address => “my@adress”
r.send_to(‘send.to@mail’) do |mail|
mail.subject = “Subject”
Dir[“*.tif”].each { | cName | mail.attach(cName) }
mail.text = “Body text”
end
Works for me.
by
TheR
Hi
In the above code, what are the libraries I need to use in require.
It says me the following error:
uninitialized constant Ruport::Report (NameError)
I have installed ruport.
Scott Lillibridge wrote:
I would suggest looking at the MailFactory gem (
http://rubyforge.org/projects/mailfactory/). It has a simple way to
construct the mail message, with attachments, that you can then send
using
net/smtp.
You can also try with Ruport:
r = Ruport::Report.new
r.add_mailer :default,
:host => “my.smtp.host”,
:address => “my@adress”
r.send_to(‘send.to@mail’) do |mail|
mail.subject = “Subject”
Dir[“*.tif”].each { | cName | mail.attach(cName) }
mail.text = “Body text”
end
Works for me.
by
TheR
Loga G. wrote:
I have installed ruport.
Awaiting reply…
Awaiting reply…
Hi
Expecting Reply …
Obviously, this is not working out for you. I haven’t seen your
original code but it seems like your need to require ruport.
Cheers,
Mohit.
3/25/2009 | 2:45 PM.
Mohit S. wrote:
Loga G. wrote:
I have installed ruport.
Awaiting reply…
Awaiting reply…
Hi
Expecting Reply …
Obviously, this is not working out for you. I haven’t seen your
original code but it seems like your need to require ruport.
Cheers,
Mohit.
3/25/2009 | 2:45 PM.
This is the code that I worked out:
#! /usr/bin/ruby
require ‘ruport’
r = Ruport::Report.new
r.add_mailer :default,
:host => “my.smtp.host”,
:address => “my@adress”
r.send_to('send.to@mail') do |mail|
mail.subject = "Subject"
Dir["*.tif"].each { | cName | mail.attach(cName) }
mail.text = "Body text"
end
Ya, the above code says the following error:
uninitialized constant Ruport::Report (NameError)
I think the module Report was not included. But though I used ‘include
Ruport::Report’ , it says the error
Loga G. wrote:
Mohit S. wrote:
Loga G. wrote:
I have installed ruport.
Awaiting reply…
Awaiting reply…
Hi
Expecting Reply …
Obviously, this is not working out for you. I haven’t seen your
original code but it seems like your need to require ruport.
Cheers,
Mohit.
3/25/2009 | 2:45 PM.
This is the code that I worked out:
#! /usr/bin/ruby
require ‘ruport’
r = Ruport::Report.new
r.add_mailer :default,
:host => “my.smtp.host”,
:address => “my@adress”
r.send_to('send.to@mail') do |mail|
mail.subject = "Subject"
Dir["*.tif"].each { | cName | mail.attach(cName) }
mail.text = "Body text"
end
Yep. Thats it.
Sorry 4 not beeing online.
by
TheR
From: Loga G. [mailto:[email protected]]
Ya, the above code says the following error:
uninitialized constant Ruport::Report (NameError)
I think the module Report was not included. But though I used 'include
Ruport::Report’ , it says the error
gem install ruport-utils
then on your code…,
require ‘ruport/util’