用附件ruby发送邮件

时间:2013-07-11 14:59:52

标签: ruby email actionmailer

我希望发送带附件的邮件。我需要在html中格式化正文,当配置格式时,文件附件在邮件中发送错误。

我的代码使用actionMailer:

#require 'mail'

class MyMail < ActionMailer::Base
  default :from => 'cristian.gonzalez@powersystem.com.ar'          

  def send_mail(user,pdffile_name,pdffile_name_second,pdffile_name_thir,htmlfile_name)

    #sendgrid_unique_args :key1 => user.id
    email_with_name = "#{user.send_user} <#{user.mail_address}>"
    #Adjuntar el archivo   1
    unless pdffile_name.nil?
      filename = user.first_attachment.partition("/")[2]    
      attachments[filename] = File.open(pdffile_name, 'rb', &:read)          
    end
    mail :to => 'cdgonzalez82@gmail.com',
         :subject = user.mail_subject, 
         :content_type = 'text/html; charset=UTF-8',
         :email.body = user.mail_body

  end
end

请帮忙???

0 个答案:

没有答案