SCHLORKE AS Andreas (DKD)
2008-Jun-23 08:35 UTC
[Tmail-talk] Adding attachment generates no boundary
hi together,
when adding an attachment to a mail I want to send via SMTP I get the
following error:
C:/localapp/apps/development/ruby/lib/ruby/gems/1.8/gems/tmail-1.2.3.1/l
ib/tmail/mail.rb:556:in `quote'': can''t convert nil into String
(TypeError)
This happens in method "read_multipart" and obviously when adding an
attachment a boundary is not created. Now I''m a little bit puzzled if I
do this wrong or if there''s a problem in the Mail class.
Here''s my code:
def setup_mail_attachments
@mail = TMail::Mail.new
@mail.date = Time.now
@mail.from = @from
@mail.to = @to
@mail.subject = @subject
@mail.mime_version = ''1.0''
@mail.set_content_type("multipart", "mixed")
mailpart1 = TMail::Mail.new
mailpart1.body = @body
mailpart1.set_content_type("text", "plain")
@mail.parts.push(mailpart1)
@attachments.each do |att|
if FileTest.exists?(att)
fname = File.basename(att)
f = File.new(att,"rb")
content = f.read
mailpart=TMail::Mail.new
mailpart.body = Base64.encode64(content)
mailpart.transfer_encoding="Base64"
mailpart.set_content_type("application",
"octet-stream")
mailpart[''Content-Disposition''] = "attachment;
filename=#{fname}"
@mail.parts.push(mailpart)
end
end
end
BTW: If I add the following code to method read_multipart in Mail class
everything works fine:
def read_multipart( src )
bound =
@header[''content-type''].params[''boundary'']
# ADDED
if bound == nil
bound = ::TMail.new_boundary
end
#END ADDED
is_sep = /\A--#{Regexp.quote bound}(?:--)?[ \t]*(?:\n|\r\n|\r)/
lastbound = "--#{bound}--"
...
end
thanks for your help
Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/tmail-talk/attachments/20080623/309d3cc5/attachment.html>
Thanks Andreas> BTW: If I add the following code to method read_multipart in Mail class > everything works fine:Could you make a test case (and patch) and submit to the tracker at tmail.rubyforge.org? Regards Mikel