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: <unique.message.id.string@example.com>
attachment: "1.txt"
END_OF_MESSAGE
smtp = Net::SMTP.start("IpAdd" , portno)
smtp.send_message msgstr, 'fromAddress, 'toAddress'
--
Posted via http://www.ruby-forum.com/.
Vetrivel Vetrivel 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: <unique.message.id.string@example.com>
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: <unique.message.id.string@example.com>
#{mess_body}
END_OF_MESSAGE
(did I win that 10,000 pound UK lotto yet?)
--
Posted via http://www.ruby-forum.com/\.
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.
···
On Sun, Mar 22, 2009 at 9:55 PM, David Wright <david_v_wright@yahoo.com>wrote:
Vetrivel Vetrivel 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: <unique.message.id.string@example.com>
> 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: <unique.message.id.string@example.com>
#{mess_body}
END_OF_MESSAGE
(did I win that 10,000 pound UK lotto yet?)
--
Posted via http://www.ruby-forum.com/\.
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
···
--
Posted via http://www.ruby-forum.com/\.
Damjan Rems 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.
···
--
Posted via http://www.ruby-forum.com/\.
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.
Awaiting reply................
···
--
Posted via http://www.ruby-forum.com/\.
Loga Ganesan wrote:
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.
Awaiting reply................
Awaiting reply................
···
--
Posted via http://www.ruby-forum.com/\.
Loga Ganesan wrote:
Loga Ganesan wrote:
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.
Awaiting reply................
Awaiting reply................
Hi
Expecting Reply .........
···
--
Posted via http://www.ruby-forum.com/\.
Loga Ganesan wrote:
Loga Ganesan wrote:
Loga Ganesan wrote:
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.
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 Sindhwani wrote:
Loga Ganesan 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
···
--
Posted via http://www.ruby-forum.com/\.
Loga Ganesan wrote:
Mohit Sindhwani wrote:
Loga Ganesan 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
···
--
Posted via http://www.ruby-forum.com/\.
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
···
--
Posted via http://www.ruby-forum.com/.
# 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'
···
From: Loga Ganesan [mailto:loganathan_gpt@yahoo.co.in]