On Thursday, 18 October 2012 at 12:21 AM, ajay paswan wrote:

> Hi,
>  
> the following function to mail with an attachment is not working, mail
> is going but Its not attaching the file:


You appear to be missing a marker somewhere. Why not use the mail gem[1] and let it handle this for you?

mail = Mail.new do
from from
to to
subject 'test subject'
body <<-BODY
Mail body

Thank you,
Programmer
BODY
add_file :filename => filename, :content => non_encoded_contentend

Now just write mail.to_s instead of mailtext per your example.
  

> Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)


This is dangerous.  Someone could intercept the connection, and possibly steal your data.

If you obtain cacert.pem from a trusted location (e.g. [2]), you can configure Net::SMTP accordingly:

Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_PEER, File.join(File.dirname(__FILE__), "..", "cacert.pem"))
> After this, how can I send multiple attachment, suppose files to attach> are in array 'a_array'?


With my above example, just call add_file multiple times, e.g. if a_array was an array of paths:

กฤ
  a_array.each do |attachment|
    add_file :filename => File.basename(attachment[:filename]),:content => File.read(attachment[:filename])
  end
กฤ  

Cheers,

Arlen

[1] https://github.com/mikel/mail
[2] http://curl.haxx.se/ca/cacert.pem