Forum: Ruby send email in ruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2d8b8b3782611eae032f194a900db4ef?d=identicon&s=25 Vetrivel Vaithilingam (vetrivel)
on 2009-03-23 05:27
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'
9440222a0c3e33f369eef79712e12204?d=identicon&s=25 David Wright (__dw5__)
on 2009-03-23 05:58
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/rdo... 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?)
3637c8ab02ad27d4548614027d1d26f3?d=identicon&s=25 Scott Lillibridge (Guest)
on 2009-03-23 06:05
(Received via mailing list)
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.
Be07c8d0d6867fd9a0d525f7d17600e2?d=identicon&s=25 Damjan Rems (ther)
on 2009-03-23 10:21
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
9b3d14efbedc70a652b441b2ec6b871b?d=identicon&s=25 Loga Ganesan (loganathan1)
on 2009-03-23 14:19
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.
9b3d14efbedc70a652b441b2ec6b871b?d=identicon&s=25 Loga Ganesan (loganathan1)
on 2009-03-24 05:35
>
> 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................
9b3d14efbedc70a652b441b2ec6b871b?d=identicon&s=25 Loga Ganesan (loganathan1)
on 2009-03-24 09:42
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................
9b3d14efbedc70a652b441b2ec6b871b?d=identicon&s=25 Loga Ganesan (loganathan1)
on 2009-03-25 07:42
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 .........
34a7615f38496a5dafbb3e6b721c435e?d=identicon&s=25 Mohit Sindhwani (Guest)
on 2009-03-25 07:46
(Received via mailing list)
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.
9b3d14efbedc70a652b441b2ec6b871b?d=identicon&s=25 Loga Ganesan (loganathan1)
on 2009-03-25 07:59
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
Be07c8d0d6867fd9a0d525f7d17600e2?d=identicon&s=25 Damjan Rems (ther)
on 2009-03-25 08:17
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
9b3d14efbedc70a652b441b2ec6b871b?d=identicon&s=25 Loga Ganesan (loganathan1)
on 2009-03-25 08:21

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
6087a044557d6b59ab52e7dd20f94da8?d=identicon&s=25 Peña, Botp (Guest)
on 2009-03-25 09:09
(Received via mailing list)
From: Loga Ganesan [mailto:loganathan_gpt@yahoo.co.in]
# 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'
This topic is locked and can not be replied to.