Rails confirmation email aol parsing error with email name - ruby-on-rails

When I get a confirmation email sent via my rails app, I use this code
<a href='mailto:John%20Doe<Johndoe#random.com>?subject=Billing%20Submission'>LINK</a>
The email that shows up in all different emails is good except for aol.
In aol, it shows up as:
?subject=Billing%20Submission'>LINK
Is there any way around this without compromising the name being added?

Replace
<a href='mailto:John%20Doe<Johndoe#random.com>?subject=Billing%20Submission'>LINK</a>
With
<a href='mailto:John%20Doe%3CJohndoe#random.com%3E?subject=Billing%20Submission'>LINK</a>
> after Johndoe#random.com was actually ending the starting tag of a (anchor).
Use URL encoding equivalent for < (%3C) and > (%3E) sign.

Related

Link to non http protocol from a Rails mailer template

I'd like to have a link in an email (opened on an iOS devise) open an iOS app.
I have Rails mailer template that contains a link, which opens the app 'myapp' on an iOS device:
<%= link_to 'Reset my password', "myapp://?password_reset_token=#{#token}" %>
This link is rendered properly when used in a regular view, displayed in a browser.
The problem is when the link is used in a mailer template it displays without the href:
<a href>Reset My password</a>
I get the same results when I put the <a> tag manually in the template instead of using link_to. Still results in blank href.
It seems that using any protocol other than http or https yields the same results.
Is there any way to make this non http link display properly
The way I got around this was to adjust my url like this:
"myapp://myapp.com?password_reset_token=#{#token}"
The addition of the 'myapp.com' part made it work, and I can just ignore that part, and parse out the query params that I need.
Above solution do not work as
when I check mail in gmail the href remove from mail, it looks like <a href>Reset My password</a>
So I have done a workaround for it
I have redirected to a route and in that I embed script as below
<script>
$(function(){
window.location = "myapp://myapp.com"+window.location.search
})()
</script>
so it will redirects with all parameters to the URI

Adding a hyperlink to 'Mailto' Body text

I am currently working on mailchimp to produce an email forwarding button. When you press this button some text appears in an appear which you then send to others. I have used the code below. I want to have a hyperlink for the "www.dailypnut.com" address as currently it appears in the email as just text. How do I do this?
<p style="background-color:#3b5998; width:200px; height:40px;
opacity:0.8;margin:auto;margin-top:15px; margin-bottom;px;
text-align:center;line-height:40px"><a href="mailto:?Subject=The Daily
Pnut:The World in a Nutshell&Body=%20Sign%20up%20for%20the%20
Daily%20Pnut.%20A%20humorous%20daily%20summary%20of%20world%20affairs
%20-%20www.dailypnut.com" style="text-decoration:none"><b style=
"color:white;text-decoration:none; opacity:0.9;text-transform: uppercase;
font-size:14px">Forward the Pnut!</b></a></p>
This behaviour depends on the e-mail client, so you won't get a solution for this in your html.
Unfortunately you can only specify a plain body in mailto (see for example MailTo with HTML body). Since a lot of e-mail clients today only allow editing of the html body, and hence 'convert' the plain body into html when it is loaded, they will most likely replace URLs with links during conversion.
The result is that the behaviour of your mailto link will be different depending on the user's email client.

How to get the email message body with ActionMailer

I am sending an standard email with Rails like this
#mail = mail(to: registration.user.email, subject: "Registration Confirmation: #{#site.name}")
Now i need to get the message body (or html in this case) from the email. I tried the following but it does not work since it returns not the rendered email but rather the template (including ERB and Haml).
#mail.body
#mail.body.raw_source
#mail.body.encoded
It seems surprisingly difficult to do this. I need the result that a persons sees when receiving the email.
Update
The ERB and Haml i saw was an HTML comment, that's why in the logs it looked like it logged ERB instead of a rendered tempalte. So #mail.body.encoded works fine.
I tried the accepted answer but it is showing the HEADER along with HTML. To get the HTML tags only I've used below code:
#mail.html_part.body.decoded
How about #mail.body.encoded (which should give you the result for which you seek)?

Rails Devise "You need to sign in or sign up before continuing"

everybody.
I was using Devise for authentication in Rails 4 and got some troubles with Devise. When I enter the link: http://yourdomain.com:3000/users/edit.535db919486f611779000000 , it just render the text "You need to sign in or sign up before continuing." without rendering layout, instead of redirect to login page (see attachment)
I guess Rails understand the numeric after "edit." is format and it didn't know how to render it.
What I want is when user enter any link without logged in, it will redirect to login page. Could anyone help me?
With this link, it throw an unknown format exception.
Your problem is to do with the passing of a value after . - EG edit.234234324 or login.23424234
As you can see from your screenshot, you're receiving the error because Rails is treating the number as a format (in the same way it would treat .html, .js or .json as formats)
I don't know why it works for edit, but it looks like it's rendering json to me, probably because it's confused with the type of format you've sent
The way to fix this is to get your config/routes.rb & URLs fixed
You've not detailed how you're sending the numbered requests to your URL helper, but if you're requesting pure URLS, you need to remove the number from the end:
localhost:3000/users/login
localhost:3000/users/edit
These are the URLs which should load (with no numbers)
I would imagine you are getting the error because you're calling the devise url helpers like this:
<%= link_to "login", user_new_session_path(some_value) %>
You just need to use user_new_session_path

How to put a button to action in an email template in RoR

My application sends notification emails to users, I would like to put a button in the email that links to a certain action in a controller?
When I put regular html code (like <input type="button" .... />, I get it in the received email as string, that is, I find the html code in the email) How can I skip this trap?
It's not a perfect idea to send messages as html. By default I turn off html in my email account.
Look this screencast for a beginning: http://railscasts.com/episodes/206-action-mailer-in-rails-3. You just need to specify different view formats: html or text for plain text. But in any case it will rely on reciever email settings which format will be choosen.

Resources