email - Ruby send mail with DSN -
using gem mail , considering http://www.sendmail.org/~ca/email/dsn.html want this:
mail = mail.new mail.delivery_method :smtp, :address => 'smtp.server.com', :port => 25 mail.from = 'sender@smtp.server.com' mail.to = '<recipient@yet.another.server.com> notify=success orcpt=rfc822;recipient@yet.another.server.com' mail.deliver!
and error:
...ruby/2.1.0/net/smtp.rb:957:in `check_response': 501 5.1.3 bad recipient address syntax (net::smtpsyntaxerror)
then try monkey-patching (i know it's dirty):
class net::smtp def rcptto(to_addr) if $safe > 0 raise securityerror, 'tainted to_addr' if to_addr.tainted? end # replace # getok("rcpt to:<#{to_addr}>") # getok("rcpt to:<#{to_addr}> notify=success,failure,delay orcpt=rfc822;#{to_addr}") end end
and works fine it's ugly (
does know more legal , beauty solution?
according documentation source code , readme page on github, need that:
mail = mail.new mail.delivery_method :smtp, address: 'smtp.server.com', port: 25 mail[:from] = 'sender@smtp.server.com' mail[:to] = '<recipient@yet.another.server.com> notify=success orcpt=rfc822;recipient@yet.another.server.com' mail.deliver!
may more elegant way be:
mail = mail.new 'sender@smtp.server.com' '<recipient@yet.another.server.com> notify=success orcpt=rfc822;recipient@yet.another.server.com' end mail.delivery_method :smtp, address: 'smtp.server.com', port: 25 mail.deliver!
Comments
Post a Comment