Salah satu kendala mengirimkan email berformat HTML adalah bagaimana melakukan
styling terhadap email HTML tersebut agar memiliki tampilan yang menarik.
Styling yang dilakukan adalah dengan menggunakan
inline CSS dan hal ini terkadang tidaklah mudah. Dengan gem yang bernama
MailStyle, maka
styling HTML tersebut menjadi lebih mudah. Berikut ini adalah
contoh penggunaanya.
class Notifier < ActionMailer::Base
def confirmation_email
css :notification
subject 'Confirm Your Registration'
recipients '[email protected]'
from '[email protected]'
sent_on Time.now
content_type 'text/html'
end
end
# public/stylesheets/notofication.css
body { background: #111; }
p { color: #fff; line-height: 1.25 }
.myclass { font-size: 15px; }
# confirmation_email.text.html.erb
I am using MailStyle
Hasilnya adalah:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /%gt;
</head>
<body style="background: #111">
<p style="color: #fff;line-height:1.25;font-size: 15px">I am using MailStyle</p>
</body>
</html>
Langkah-langkah instalasi:
gem install nokogiri css_parser
Kemudian install gem mail_style
gem install mail_style
atau plugin mail_style
ruby script/plugin install http://github.com/purify/mail_style
Info lebih lanjut:
0 comments:
Post a Comment