Fwd: [RAILS4] How to escape HTML characters in email in rails mailer

163 views
Skip to first unread message

Loganathan Sellapa

unread,
Mar 5, 2015, 3:02:07 PM3/5/15
to bangal...@googlegroups.com
Hi All,

I want to escape some of my email contents which are all having special characters such as below, what is best way to do it, html_safe, h, & raw didn

​'​
t escape the HTML characters in mailer views.

"password<>"
"password<br><d>test"
regards,
Loganathan
Mob: +91 7760780741 | +91 9944414388
Skype: loganathan.sellappa
ViewMe


Satish Kota

unread,
Mar 5, 2015, 10:29:22 PM3/5/15
to bangal...@googlegroups.com

raw should work….i use it in my system….

--
You received this message because you are subscribed to the Google Groups "BANGALORE RUG-Ruby Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bangalorerug...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Loganathan Sellapa

unread,
Mar 6, 2015, 8:17:51 AM3/6/15
to bangal...@googlegroups.com
I have tried raw/h/html_safe already none of them are working mailer views :(

regards,
Loganathan
Mob: +91 7760780741 | +91 9944414388
Skype: loganathan.sellappa
ViewMe


Amit K Mathur

unread,
Mar 6, 2015, 9:00:17 AM3/6/15
to bangal...@googlegroups.com
On Friday 06 March 2015 06:47 PM, Loganathan Sellapa wrote:
I have tried raw/h/html_safe already none of them are working mailer views :(

Perhaps you can post snippet of your mailer view and snippet of the output you are getting.

Regards,
Amit.

Loganathan Sellapa

unread,
Mar 6, 2015, 9:03:58 AM3/6/15
to bangal...@googlegroups.com

Locale File

email_root_password: |
                       Your new cell has been created!<br><br>You can access it using the following credentials:<br> IP Address: %{ip_address}<br> Username: root
                       <br> Password: %{password}<br><br><br>You can change your password or add your SSH key(s) be editing the cell details here: <a href='%{cell_access_link}'>%{cell_access_link}</a>

Mailer View

!!!
%html
  %body
    %p
    %meta{content: "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
    %div
     = t("email_contents.email_root_password",  ip_address: @vm["ip_addresses"][0]["ip_address"]["address"], password: @vm['initial_root_password'], cell_access_link: cell_url(@vm['id'])).html_safe

regards,
Loganathan
Mob: +91 7760780741 | +91 9944414388
Skype: loganathan.sellappa
ViewMe


--

Amit K Mathur

unread,
Mar 6, 2015, 9:12:50 AM3/6/15
to bangal...@googlegroups.com
You didn't show the output. Anyway, my guess is - you should have email_contents.email_root_password.html_safe instead of at the end of the method.

Loganathan Sellapa

unread,
Mar 6, 2015, 9:18:08 AM3/6/15
to bangal...@googlegroups.com
This is the output of the email, and FYI html_safe is at the email_contents.email_root_password.html_safe only

Output:

Your new cell has been created!

You can access it using the following credentials:
IP Address: 64.22.114.187
Username: root 
Password: 

You can change your password or add your SSH key(s) be editing the cell details here: http://localhost.com/cells/649
​Where 

password value is <r0#42!c6$qU​

regards,
Loganathan
Mob: +91 7760780741 | +91 9944414388
Skype: loganathan.sellappa
ViewMe


Amit K Mathur

unread,
Mar 6, 2015, 9:23:41 AM3/6/15
to bangal...@googlegroups.com

On Friday 06 March 2015 07:47 PM, Loganathan Sellapa wrote:
t("email_contents.email_root_password",  ip_address: @vm["ip_addresses"][0]["ip_address"]["address"], password: @vm['initial_root_password'], cell_access_link: cell_url(@vm['id'])).html_safe


Sorry, I misunderstood your code earlier. Change the above line to:

t("email_contents.email_root_password",  ip_address: @vm["ip_addresses"][0]["ip_address"]["address"], password: @vm['initial_root_password'].html_safe, cell_access_link: cell_url(@vm['id']))

Note that you want to the password string to be tagged as html_safe.

Loganathan Sellapa

unread,
Mar 6, 2015, 9:25:07 AM3/6/15
to bangal...@googlegroups.com
I have already tried it, no luck

regards,
Loganathan
Mob: +91 7760780741 | +91 9944414388
Skype: loganathan.sellappa
ViewMe


--

Amit Mathur

unread,
Mar 6, 2015, 9:55:23 AM3/6/15
to bangalorerug
Is your problem that password is not printed in the output email when it has a "<" in it ?

Then, you can try:

t("email_contents.email_root_password",  ip_address: @vm["ip_addresses"][0]["ip_address"]["address"], password: h(@vm['initial_root_password']), cell_access_link: cell_url(@vm['id'])).html_safe

Loganathan Sellapa

unread,
Mar 6, 2015, 10:00:01 AM3/6/15
to bangal...@googlegroups.com
Amit, 

Please read my previous emails, I've tried all the methods h, raw & html_safe. I root cause of the issue is with I18n + html escape,  not with the mailer view. I am still figuring out the way to fix the issue in i18n, if you have any idea about it please let me know

regards,
Loganathan
Mob: +91 7760780741 | +91 9944414388
Skype: loganathan.sellappa
ViewMe


Amit K Mathur

unread,
Mar 6, 2015, 10:01:00 AM3/6/15
to bangal...@googlegroups.com
Sorry, I will pass.

Amit K Mathur

unread,
Mar 6, 2015, 10:01:59 AM3/6/15
to bangal...@googlegroups.com
Also, please share once you have solved it.


On Friday 06 March 2015 08:29 PM, Loganathan Sellapa wrote:

Gorav Bhootra

unread,
Mar 9, 2015, 12:42:03 PM3/9/15
to bangal...@googlegroups.com
Hi,

Sometimes its the issue with encoding. I used https://github.com/brianmario/charlock_holmes gem in the past while parsing incoming emails, which was effective. I don't know if its relevant here but may be worth a try.

Regards,
Gorav
skype: goravbhootra
Reply all
Reply to author
Forward
0 new messages