You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to extend Mail::Message to provide a default 'from' address by wrapping the old initialize with my own which would first call the old initialize, then set defaults, then instance_eval if a block was specified, and finally return self. All seemed to go well until I tried to override from= inside the block. This resulted in a message that, when delivered, raised this error:
NoMethodError: undefined method `addresses' for #<Mail::OptionalField:0xb72ab068>
from /home/ben/.gem/ruby/1.8/gems/mail-1.3.0/lib/mail/field.rb:120:in `send'
from /home/ben/.gem/ruby/1.8/gems/mail-1.3.0/lib/mail/field.rb:120:in `method_missing'
from /home/ben/.gem/ruby/1.8/gems/mail-1.3.0/lib/mail/network/delivery_methods/smtp.rb:60:in `deliver!'
from /home/ben/.gem/ruby/1.8/gems/mail-1.3.0/lib/mail/network/deliverable.rb:11:in `perform_delivery!'
from /home/ben/.gem/ruby/1.8/gems/mail-1.3.0/lib/mail/message.rb:68:in `deliver!'
from (irb):20
from /home/ben/.gem/ruby/1.8/gems/treetop-1.4.2/lib/treetop/compiler/metagrammar.rb:415
First, I thought the problem might be that I now had multiple 'from' addresses and went to RFC 822 to see if that even made sense. Indeed, multiple authorship is valid, provided a single 'Sender' is specified, but when I inspected the message in irb, I did not find that multiple authorship had been set. Instead, I noticed something very odd about the message that results from trying to call 'from' twice, and that is that FromField is removed and replaced with an OptionalField with @name==:from (I have thrown some debug print statements in to see when we're doing an 'update' vs. 'create'):
Of course, to work around this problem, I could make users delete from after establishing the default to set a new value, but that's not very friendly, e.g.
Ideally, what I would like mail.from= to do is to replace the old from address with the new. But failing that, I would like some way to specify a default 'from' address to use that, if no from address was specified by the time the message is delivered, would be used.
The text was updated successfully, but these errors were encountered:
Good catch. I have fixed this in commit fa257d6..001a868. It will be included in the next gem release. It is a very simple fix if you want to patch your copy of mail.
I tried to extend Mail::Message to provide a default 'from' address by wrapping the old initialize with my own which would first call the old initialize, then set defaults, then instance_eval if a block was specified, and finally return self. All seemed to go well until I tried to override from= inside the block. This resulted in a message that, when delivered, raised this error:
First, I thought the problem might be that I now had multiple 'from' addresses and went to RFC 822 to see if that even made sense. Indeed, multiple authorship is valid, provided a single 'Sender' is specified, but when I inspected the message in irb, I did not find that multiple authorship had been set. Instead, I noticed something very odd about the message that results from trying to call 'from' twice, and that is that FromField is removed and replaced with an OptionalField with @name==:from (I have thrown some debug print statements in to see when we're doing an 'update' vs. 'create'):
Of course, to work around this problem, I could make users delete from after establishing the default to set a new value, but that's not very friendly, e.g.
Ideally, what I would like mail.from= to do is to replace the old from address with the new. But failing that, I would like some way to specify a default 'from' address to use that, if no from address was specified by the time the message is delivered, would be used.
The text was updated successfully, but these errors were encountered: