How to do the attachment in mail like the yahoo and gmail does?
<% form_tag(depot_help_desk_path, :method => :post, :multipart =>
true) do %>
<%= radio_button "helpdesk", "browser", "Safari" %>Safari
<%= radio_button "helpdesk", "browser", "Mozilla Firefox" %>Mozilla Firefox
<div style="width: 300 px;">2. Ik werk met de volgende computer:</
div>
<%= radio_button “helpdesk”, “os”, “windows” %>Windows
<%= radio_button “helpdesk”, “os”, “mac” %>Mac
<%= radio_button “helpdesk”, “os”, “linux” %>Linux
<div style="width: 300 px;">3. Mijn gebruikersnaam is:</div>
<label id="label_right"><%= text_field 'helpdesk',
‘user_name’, :class => “txtfield”, :size => 20 %>
<div style="width: 300 px;">4. Mijn e-mail adres is:</div>
<label id="label_right"><%= text_field 'helpdesk',
‘email’, :class => “txtfield”, :size => 20 %>
<div style="width: 400 px;">5. Het probleem is op de volgende
datum opgetreden:
<%= text_field ‘helpdesk’, ‘datum’, :class
=> “txtfield”, :size => 20 %>
<div style="width: 300 px;">6. De URL waar het probleem zich
voordoet is:
<%= text_field ‘helpdesk’, ‘url’, :class
=> “txtfield”, :size => 20 %>
<div style="width: 300 px;">7. Bestand toevoegen:</div>
<%= file_field 'helpdesk', 'file', :class => "txtfield", :size =>
20 %>
<div style="width: 300 px;">8. Het originele bestand heb ik
bijgevoegd:
<%= radio_button “helpdesk”, “bestand”, “ja” %>ja
<%= radio_button “helpdesk”, “bestand”, “nee” %>nee
<div style="width: 550 px;">9. Graag zo volledig mogelijk
omschrijven (stapsgewijs) wat het probleem / je vraag is.
<%= text_area ‘helpdesk’, ‘text’, :cols =>
“70”, :rows => 20 %>
<div style="width: 550 px;">Hartelijk dank voor het invullen van
bovenstaand formulier. Klik op versturen en wij streven ernaar binnen
5 werkdagen te reageren.
<div><%= submit_tag "versturen", :onClick => "", :id => 'disable-
me’ %>
def ticket_with_attachment(browser, os, email, user_name, datum,
url, file, bestand, text, sent_at = Time.now )
@subject = 'Helpdesk verzoek: ’ + user_name
@body = { :browser => browser, :os => os, :user_name =>
user_name, :email => email, :datum => datum, :url => url, :bestand =>
bestand, :text => text }
@recipients = “[email protected]”
@from = “[email protected]”
@sent_on = sent_at
unless file.blank?
attachment :body => file.read, :filename =>
file.original_filename
end
end
That’s working code from one of our apps. Not very nice looking, but
should do.
Important parts are the file_field in the form (all others are just
text or radio buttons)
and those lines in the ActionMailer delivery method:
unless file.blank?
attachment :body => file.read, :filename => file.original_filename
end
which will attach the file to the mail
Thank you Muller I will try it and let you know the oucome.
I read your code and do something like this in my actionmailer class
def contact(recipient, subject, message,user_id,attachment1=nil,
sent_at = Time.now)
@body[‘user_id’]= user_id
@subject = subject
@recipients = recipient
@from = '[email protected]'
@sent_on = sent_at
@body["title"] = 'You have new Job Application'
@body["message"] = message
unless attachment1.nil?
attachment "application/octet-stream" do |a|
a.body=attachment1.read
a.filename=attachment1.original_filename
end
end
attachment :content_type=>"image/jpeg",
:body=>File.read("#{RAILS_ROOT}/public/images/
afterpinkslip.jpg"),
:filename=>File.basename("#{RAILS_ROOT}/public/images/
afterpinkslip.jpg")
end
and it works beautifully. Thank you once again.