How to put a button to action in an email template in RoR - ruby-on-rails

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.

Related

Mailboxer html formattting

How can I allow Mailboxer gem to send HTML formatted messages?
For example, I want the first message user A sends to user B to be pre-formatted with certain text and HTML tags. Currently any kind of markup is escaped..
EDIT: My question is basically how can I "patch" the send_message functionality? Or create a new send_message2 that behaves the way I want?

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.

Using Render in my .rb file

Hi I have some html in a file called (a partial):
_quotemail.html.erb
I Am sending an email to a user and I want to put this html in the email. I am using mailgun.
I can define my email body like so:
body = "text to go in email"
which works great but I want to instead include the HTML I have in my quotemail partial.
Whats the best way to do this?

Thymeleaf - Configure mail subject in template

I am using Thymeleaf templates for generating email contents and send using spring mailSender. Is there any option to specify the email subject within the thymeleaf template itself?
You can define fragments in your template and render those parts only.
<div th:fragment="subject">
Mail subject
</div>
<div th:fragment="body">
Mail body
</div>
That's a basic HTML thing
Send mail
you can add also the ?body= if you want to add content in your mail.
Edit: According to your comment, you want to put a input on a page and write a subject and get it in Java.
Put a form with an input in your thymeleaf template and post it to your server, get the value in your controller and use it to send your mail.
Do you need code example for this ?

reuse of mvc view

I'm working on the MVC app where I've to generate the report in the form of HTML page. If the user click the print icon, I've to show the HTML page to user. If the user click on email icon, I've to send email with same HTML page attachment. I'm trying to find a way where I can use the same code to generate the HTML in both cases of email and print. Please provide your suggestions.
What you really want and did not know how to formulate is Render view to string. Then you can do whatever you want with the contents of that string.
Start here
Render a view as a string
but this subject continues in many other questions too (or you can Google it) and you will discover much more information.
Your Controller has to decide what to do.
User clicked print. Controller action: collect data, prepare the View, display as HTML page
User clicked email. Controller action: collect data, prepare the View, call on an email-function and use the output of the HTML page as an attachment.

Resources