We have Ruby On Rails application with some emails subscription. It has mailer class inherited from ActionMailer:
class UserMailer < ActionMailer::Base
...
end
Everything ok, except one thing - some users have email addresses with "-" at begin. It occur errors when I'm trying send email to "[email protected]":
sendmail: invalid option -- u
sendmail: invalid option -- s
sendmail: invalid option -- u
sendmail: fatal: usage: sendmail [options]
How could I escape this character(and maybe some similar) for ActionMailer?
Thanks
The short answer is yes, email addresses can include these characters, but with some exceptions. The two biggest factors to consider are hyphen placement and email service provider.
A dash is longer than a hyphen and is commonly used to indicate a range or a pause. The most common types of dashes are the en dash (–) and the em dash (—).
The URI.escape method although deprecated does take a second parameter that lets you mark what's unsafe like so
URI.escape("[email protected]", '-')
=> "%[email protected]"
CGI escape which replaces URI.escape doesn't seem to have the same functionality but for a single case like this it might work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With