[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

send email in ruby

Vetrivel Vetrivel

3/23/2009 4:24:00 AM

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-....

12 Answers

david wright

3/23/2009 4:56:00 AM

0

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/... 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-....

Scott Lillibridge

3/23/2009 5:02:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

I would suggest looking at the MailFactory gem (
http://rubyforge.org/projects/ma...). 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/... 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-....
>
>

Damjan Rems

3/23/2009 9:19:00 AM

0

Scott Lillibridge wrote:
> I would suggest looking at the MailFactory gem (
> http://rubyforge.org/projects/ma...). 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-....

Loga Ganesan

3/23/2009 1:16:00 PM

0

Damjan Rems wrote:
> Scott Lillibridge wrote:
>> I would suggest looking at the MailFactory gem (
>> http://rubyforge.org/projects/ma...). 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-....

Loga Ganesan

3/24/2009 4:32:00 AM

0

>
> 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-....

Loga Ganesan

3/24/2009 8:39:00 AM

0

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-....

Loga Ganesan

3/25/2009 6:40:00 AM

0

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-....

Mohit Sindhwani

3/25/2009 6:42:00 AM

0

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.


Loga Ganesan

3/25/2009 6:56:00 AM

0

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-....

Damjan Rems

3/25/2009 7:14:00 AM

0

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-....