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
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
Mail.defaults do
delivery_method :smtp, options
end
Mail.deliver do
from 'example@gmail.com'
to %w(me@here.comyou@there.com)
subject 'Test'
body 'Test email'
if attachments.size != 0 && attachments[0]
attachments.each {|filename|
add_file(filename)
}
end
end