Could you please post a program to send mail without using Action Mailer

require 'net/smtp'

def send_email(to,opts={})
  opts[:server] ||= 'localhost'
  opts[:from] ||= 'email@example.com'
  opts[:from_alias] ||= 'Example Emailer'
  opts[:subject] ||= "You need to see this"
  opts[:body] ||= "Important stuff!"

  msg = <<END_OF_MESSAGE

···

From: #{opts[:from_alias]} <#{opts[:from]}>
To: <#{to}>
Subject: #{opts[:subject]}

#{opts[:body]}
END_OF_MESSAGE

  Net::SMTP.start(opts[:server]) do |smtp|
    smtp.send_message msg, opts[:from], to
  end
end
I tried this but it doesn"t work

--
Posted via http://www.ruby-forum.com/.

Define "doesn't work". Do you get an error message?

There are these alternatives that I know of:
https://rubygems.org/gems/pony
https://rubygems.org/gems/mail

···

--
Posted via http://www.ruby-forum.com/.

Here is an example that works in Ruby 1.8.6.
Comments are in english but the receivers are french speaking people...
Mind the blank lines in the mailtext variable.

def send_general

···

#===============#
# send the file "fichier_html" via SMTP to the adresses contained in the
file "Destinataires.txt" with a text

# read the file and base64 encoding
  filecontent = File.read(@fichier_html)
  encodedcontent = [filecontent].pack("m") # base64

# read the "to" adresses
  dest = Array.new
  IO.foreach("Destinataires.txt") { |ligne|
    ligne.chomp!
    if not ligne.empty? then dest.push(ligne) end }
  marker = "==_batilus123456_=="

# message text
  body =<<EOF
Veuillez trouver ci-joint les résultats de : #{@laRegate.nomReg} du
#{@laRegate.date}

Commentaire : #{@commentEntry.text}

Le B.V.B.M.G.H.

N.B.: Veuillez ne pas répondre à ce courriel qui vous a été envoyé
automatiquement
EOF

# header text
  part1 =<<EOF
Subject: CVBM : resultats de regate
From: CVBM <contact@bvbmgh.fr>
To: Destinataires <destinataires@bvbmgh.fr>
Content-Type: multipart/mixed; boundary=\"#{marker}\"
MIME-Version: 1.0

--#{marker}
EOF

# message definition text
  part2 =<<EOF
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding:8bit

#{body}

--#{marker}
EOF

# attachment definition
  part3 =<<EOF
Content-Type: application/htm; name=\"#{@fichier_html}\"
Content-Transfer-Encoding:base64
Content-Disposition: attachment; filename=\"#{@fichier_html}\"

#{encodedcontent}

--#{marker}--
EOF

  mailtext = part1 + part2 + part3
  mes = "Résultats envoyé à :"
  dest.each { |d| mes = mes + "\n" + d }

# Send the message
  begin
    Net::SMTP.start('smtp.orange.fr') { |smtp| smtp.sendmail(mailtext,
'michel.revesche@wanadoo.fr', *dest) }
    self.infoBox(@geneDialog, mes) # display information
  rescue Exception => e
    self.erreurBox(@geneDialog, e) # display error
  end
  end

Here's the sort of thing I do using the mail gem. You can use gmail's
smtp server if you have a gmail account set up:

require 'mail'

options = {
  :address => 'smtp.gmail.com',
  :port => 587,
  :user_name => 'example@gmail.com',
  :password => 'password',
  :authentication => 'plain',
  :enable_starttls_auto => true
}

Mail.defaults do
  delivery_method :smtp, options
end

Mail.deliver do
  from 'example@gmail.com'
  to %w(me@here.com you@there.com)
  subject 'Test'
  body 'Test email'
  if attachments.size != 0 && attachments[0]
    attachments.each {|filename|
      add_file(filename)
    }
  end
end

···

--
Posted via http://www.ruby-forum.com/.

I ran your example and it works fine. Have you looked in you email logs?

···

On Wed, Feb 20, 2013 at 9:23 AM, chandan mallik <lists@ruby-forum.com>wrote:

require 'net/smtp'

def send_email(to,opts={})
  opts[:server] ||= 'localhost'
  opts[:from] ||= 'email@example.com'
  opts[:from_alias] ||= 'Example Emailer'
  opts[:subject] ||= "You need to see this"
  opts[:body] ||= "Important stuff!"

  msg = <<END_OF_MESSAGE
From: #{opts[:from_alias]} <#{opts[:from]}>
To: <#{to}>
Subject: #{opts[:subject]}

#{opts[:body]}
END_OF_MESSAGE

  Net::SMTP.start(opts[:server]) do |smtp|
    smtp.send_message msg, opts[:from], to
  end
end
I tried this but it doesn"t work

--
Posted via http://www.ruby-forum.com/.