Mystery encoding problem sending email


#1

How in the !@#$% can this function:

def sendMsg(msg, today, cancel)

email = <<MSG
Date: #{Time.now}
From: removed_email_address@domain.invalid
Subject: Pediatric Cardiology Apt#{cancel ? ’ Cancellation’ : ‘’}
Mime-Version: 1.0
Content-Type: text/html; charset=“utf-8”;
X-Priority: #{today ? ‘1’ : ‘3’}

#{msg.encode(‘US-ASCII’, {undef: :replace, invalid: :replace})}
MSG

Net::SMTP.start(“removed_email_address@domain.invalid”, 25) do |smtp|
smtp.send_mail(email, MAILUSER, [“removed_email_address@domain.invalid”])
end

end

intermittently produce this error:

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/protocol.rb:325:in
slice!': invalid byte sequence in US-ASCII (ArgumentError) from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/protocol.rb:325:inblock in each_crlf_line’
from
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/protocol.rb:336:in
block in buffer_filling' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/protocol.rb:334:instep’
from
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/protocol.rb:334:in
buffer_filling' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/protocol.rb:324:ineach_crlf_line’
from
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/protocol.rb:269:in
write_message_0' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/protocol.rb:284:inblock (2 levels) in write_message’
from
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/protocol.rb:313:in
using_each_crlf_line' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/protocol.rb:283:inblock in write_message’
from
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/protocol.rb:202:in
writing' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/protocol.rb:282:inwrite_message’
from
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/smtp.rb:899:in
block in data' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/smtp.rb:942:incritical’
from
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/smtp.rb:896:in
data' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/smtp.rb:663:inblock in send_message’
from
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/smtp.rb:852:in
rcptto_list' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/smtp.rb:663:insend_message’
from /pedcard/scripts/SoarianReport.rb:24:in `block in sendMsg’

This is on OS X, and it only happens when run automatically from a
launch daemon. Logging into the same account and running it manually
always works. So it’s some version or configuration issue. But I find
that using rvm on OS X is frustrating to say the least…

Any clue as to where this bug comes from? Ruby update needed? Some gem
or other? What version?


Scott R.
removed_email_address@domain.invalid
http://www.elevated-dev.com/
(303) 722-0567 voice


#2

On Tuesday, January 20, 2015 at 10:07:01 AM UTC-5, Scott R. wrote:

Content-Type: text/html; charset=“utf-8”;

intermittently produce this error:

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/protocol.rb:325:in

`slice!’: invalid byte sequence in US-ASCII (ArgumentError)

[snip stack trace]

It’s curious that you are setting the message encoding to UTF-8 and then
encoding the message in US-ASCII, but it’s been a long time since I’ve
used
Net::SMTP directly. Glancing through the stack trace, it appears it may
be
puking when trying to encode the rcpt address, not necessarily the
message
itself, but to find out more would require a bit of digging in the
Net::SMTP gem code.

This is on OS X, and it only happens when run automatically from a
launch

daemon. Logging into the same account and running it manually always works.
So it’s some version or configuration issue. But I find that using rvm on
OS X is frustrating to say the least…

I can’t imagine not using RVM anymore, and the primary unix I’ve
worked
with for some years is Mac OS X. A bit of googling has always helped
me
fix or work around any issues I might have had. Having the same Ruby
environment in production as development is very helpful.

Also, I would guess the email is being sent from a rake task? Any
particular reason to use a launch daemon instead of cron?

Jim Crate