I am using gem mail for sending emails from my ruby application.
def send_results(user_id,filenames)
@user=User.find(user_id)
mail=Mail.new do
from "lalal.de"
html_part do
body File.read("/home/kik/Desktop/lal/app/views/user_mailer/analysis_process_email.html.erb")
body
end
end
"/home/kik/Desktop/lal/app/views/user_mailer/analysis_process_email.html.erb" is aa html template, where I need to pass the variable filenames.
It looks something like this:
<!DOCTYPE html>
<html>
<body>
<div id="wrapper_mail">
<div id="wrapper_mail_top">
<h4>Welcome </h4>
<br />
<p>
<br />
<br />
Your files are: <%= filenames %><br />
<br />
m
</p>
</div><!-- end wrapper_top -->
lalala
So, I want to display the content of the the variable filenames in the email but it does not work and I do not know how to make it works. Thanks in advance
I had some similar issues. Here's my setup that solved it:
def feedback_notice(message)
@sender = message.sender_id
@message = message.content
template = ERB.new(File.read('app/views/user_mailer/feedback_notice.text.erb')).result(binding)
mail = Mail.new do
from 'from@email.com'
to 'to@email.com'
subject 'My Subject Line'
body template
end
mail.deliver!
end
Seems like the .result(binding)
fixed it for me.
In the file app/views/user_mailer/feedback_notice.text.erb
I was able to access the variables @sender
and @message
May be this will help you:
File.read("/home/kik/Desktop/lal/app/views/user_mailer/analysis_process_email.html.erb").gsub("<%= filenames %>", "cat").
Thanks.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.