Mail attachment from form file field and send mail through sidekiq
NickName:Shree Ram Neupane Ask DateTime:2015-07-21T13:03:34

Mail attachment from form file field and send mail through sidekiq

In rails, I want to send email using Action Mailer with attachment that is obtained from form file field and want to delay it through sidekiq.

And I have written code as below.

In view:

<%= form_tag({ controller: 'my_controller', action: 'my_mail', method: 'post' }, { multipart: true }) do %>
    <%= form_field_tag(:attachment) %>
<% end %>

In controller:

def my_mail
    MyMailer.delay.my_mail(params)
end

In Mailer:

def my_mail(message)
    attachments['attachment'] = File.read(message[:attachment].tempfile)
    mail(from: ENV['MY_MAIL'], to: ENV['MAIL_RECIVER'], subject: 'this is subject')
end

But, IOError will be raised due to inaccessibility to the file.

And, I perform File read operation in controller as

def my_mail
   MyMailer.delay.my_mail(File.read(params[:attachment].tempfile))
end

Now, I can make attachment in Mailer as

attachments['attachment'] = message

And Now, It does work as i want but It's very bad to read file in controller due to security reason.

So, Now I want to know the best way to attach the file obtained from form and send it through sidekiq.

Copyright Notice:Content Author:「Shree Ram Neupane」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/31530750/mail-attachment-from-form-file-field-and-send-mail-through-sidekiq

More about “Mail attachment from form file field and send mail through sidekiq” related questions

Mail attachment from form file field and send mail through sidekiq

In rails, I want to send email using Action Mailer with attachment that is obtained from form file field and want to delay it through sidekiq. And I have written code as below. In view: &lt;%=

Show Detail

send mail with doc file attachment

i am sending an e-mail with a doc file attachment. I am receiving the mail but with no any attachment. PHP $file_resume = ''; if (!empty($_FILES['attachment_file_name']['tmp_name'])) { $file = $...

Show Detail

Empty attachment on mails send through zend mail

I am using Zend framework 1.12. Basically, I am trying to send attachments (images, pdf) from one of my site using Zend mail. The mail is sent and I received it in a perfect way. But the problem th...

Show Detail

PHP form send to Mail with file attachment

I have a script for PHP form send to Mail with file attachment but it did not have a function to valid the file size and file extension. php code below ### Attachment Preparation ### $file_attac...

Show Detail

phpmailer & ajax : file attachment with the mail

I have a working contact form so a user can email me while not having to refresh the page, using ajax. I'd like my user to have the option to attach a file with his email, but I'm kind of lost a...

Show Detail

Mail send form with attachment to stay on the same page

I have a "Send mail" form in my webapp that allow users to send comments or suggestions about my app. At first I created a simple POST form that worked nicely, and after sending the mail reloaded the

Show Detail

Is there any way that I can send a mail with a file attachment through SoapUI

I would like to send a mail through SoapUI with a file attachment so SoapUI has the Send mail step but it doesn't have the facility to attach a file. Is there any way to handle this?

Show Detail

send mail with attachment ruby

I want send mail with an attachment file. I need have then format body text in html, when configure the format, the file attachment sent bad in the mail. My code using actionMailer: #require 'ma...

Show Detail

Error from send Net.Mail from gmail with attachment

I don't send gmail from four attachment { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress(Form4....

Show Detail

Django mail attachment is blank

I am trying to send a mail with an attachment using Django, the attached file is sent to the server from a user submitted form. My code is shown below form = RequestForm(request.POST, request.FIL...

Show Detail