lib/mailgun/messages/message_builder.rb
def add_file(disposition, filedata, filename)
      attachment = File.open(filedata, 'r') if filedata.is_a?(String)
      attachment = filedata.dup unless attachment

      fail(Mailgun::ParameterError,
        'Unable to access attachment file object.'
      ) unless attachment.respond_to?(:read)

      if attachment.respond_to?(:path) && !attachment.respond_to?(:content_type)
        mime_types = MIME::Types.type_for(attachment.path)
        content_type = mime_types.empty? ? 'application/octet-stream' : mime_types[0].content_type
        attachment.instance_eval "def content_type; '#{content_type}'; end"
      end

      unless filename.nil?
        attachment.instance_variable_set :@original_filename, filename
        attachment.instance_eval 'def original_filename; @original_filename; end'
      end
      set_multi_complex(disposition, attachment)
    end
# Private: Adds a file to the message.
#
# @param [Symbol] disposition The type of file: :attachment or :inline
# @param [String|File] attachment A file object for attaching as an attachment.
# @param [String] filename The filename you wish the attachment to be.
# @return [void]
#
# Returns nothing
Adds a file to the message.
Adds a file to the message .
def add_file(disposition, filedata, filename)
      attachment = File.open(filedata, 'r') if filedata.is_a?(String)
      attachment = filedata.dup unless attachment
      fail(Mailgun::ParameterError,
        'Unable to access attachment file object.'
      ) unless attachment.respond_to?(:read)
      if attachment.respond_to?(:path) && !attachment.respond_to?(:content_type)
        mime_types = MIME::Types.type_for(attachment.path)
        content_type = mime_types.empty? ? 'application/octet-stream' : mime_types[0].content_type
        attachment.instance_eval "def content_type; '#{content_type}'; end"
      end
      unless filename.nil?
        attachment.instance_variable_set :@original_filename, filename
        attachment.instance_eval 'def original_filename; @original_filename; end'
      end
      set_multi_complex(disposition, attachment)
    end
def add_file ( disposition , filedata , filename ) attachment = File . open ( filedata , 'r' ) if filedata . is_a? ( String ) attachment = filedata . dup unless attachment fail ( Mailgun :: ParameterError , 'Unable to access attachment file object.' ) unless attachment . respond_to? ( :read ) if attachment . respond_to? ( :path ) && ! attachment . respond_to? ( :content_type ) mime_types = MIME :: Types . type_for ( attachment . path ) content_type = mime_types . empty? ? 'application/octet-stream' : mime_types [ 0 ] . content_type attachment . instance_eval "def content_type; '#{content_type}'; end" end unless filename . nil? attachment . instance_variable_set :@original_filename , filename attachment . instance_eval 'def original_filename; @original_filename; end' end set_multi_complex ( disposition , attachment ) end
Private: Adds a file to the message.
Private : Adds a file to the message .
None
void
disposition
filedata
filename
filename The filename you wish the attachment to be.
filename The filename you wish the attachment to be .