byCoder
byCoder

Reputation: 9184

ruby on rails mailer and non-unicode domain (.рф)

my rails app use russian cyrryllic domain name (.рф), and there I have mailer, where i have default from section...

like this:

  default from: "noreply@портал.рф"

some part of mailer:

class CarMailer < ActionMailer::Base
  default from: "noreply@портал.рф"


  def send_car_question_back(question_text, question_email, question_phone, car_user, car)
    ****
    mail(to: @question_email, subject: "***")
  end
end

but on my mailbox i get noreply@blablabla with some strane numbers( like spam :)

are there any ways to send mail, and put sender in cyryllic format?

in env confg i have:

config.action_mailer.smtp_settings =  {
    :enable_starttls_auto => false,
    :address        => 'localhost',
    :port           => 25,
    :domain         => 'xn----7s454545*****i',
    :authentication => :login,
    :content_type   => "text/html",
    :user_name      => 'noreply@xn----7s454545*****i',
    :password       => '*****'
  }
  config.action_mailer.default_url_options = { :host => 'xn----7s454545*****i' }

Upvotes: 3

Views: 768

Answers (1)

Малъ Скрылевъ
Малъ Скрылевъ

Reputation: 16507

That 'xn----7s454545*****i' is normal domain encoding for cyrillic domains, exactly for non-ASCII domains. The domain names conversion approach is described in RFC 3490.

Your mailbox just isn't support non-ASCII domain conversion. So you just can try to set domain name in mailer settings as a cyrillic one, and using a IDNA conversion gems to convert it to an ASCII form:

  1. For it is the idn gem .

     require 'idn'
    

And environment config:

    config.action_mailer.smtp_settings =  {
      #...
      :domain         => IDN::Idna.toASCII('портал.рф')
    }

And vise-versa:

    puts 'Idna.toUnicode: ' + IDN::Idna.toUnicode('xn--rksmrgs-5wao1o.josefsson.org')
  1. For you have to use simpleidn gem.

     require 'idn'
    
     SimpleIDN.to_ascii("портал.рф")
    
     SimpleIDN.to_unicode("xn--mllerriis-l8a.com")
    

Upvotes: 3

Related Questions