Closed brandonparsons closed 11 years ago
You would have to construct a new mail
since this isn't really an email anymore, it's a POST request. Happy to post the snippet if it's still needed
HI there - I only have a super basic knowledge of how to put together mail
objects in Ruby/Rails (just enough to be able to send basic transactional
email). If you could post a snippet of how to extract the attachments from
the Griddler::Email
object and attach them straight to a Mail
object
that would get me right on my way!! Thanks!
On Tue, Feb 12, 2013 at 7:06 AM, Swift notifications@github.com wrote:
You would have to construct a new mail since this isn't really an email anymore, it's a POST request. Happy to post the snippet if it's still needed
— Reply to this email directly or view it on GitHubhttps://github.com/thoughtbot/griddler/issues/22#issuecomment-13433678.
Essentially you would want to have a mailer that had something like this:
app/mailers/test_mailer.rb
class TestMailer < ActionMailer::Base
def forward_from_incoming_post(email)
email.attachments.each do |attachment|
attachments[attachment.original_filename] = attachment.read
end
mail(:to => "swift@sendgrid.com", :from => email.from, subject => email.subject)
end
end
And in your email_processor.rb
you would do something like this:
class EmailProcessor
def self.process(email)
TestMailer.forward_from_incoming_post(email).deliver!
end
end
Thank you very much! I'll give that a shot tonight.
On Tue, Feb 12, 2013 at 8:06 AM, Swift notifications@github.com wrote:
Essentially you would want to have a mailer that had something like this:
app/mailers/test_mailer.rb
class TestMailer < ActionMailer::Base def forward_from_incoming_post(email) email.attachments.each do |attachment| attachments[attachment.original_filename] = attachment.read end
mail(:to => "swift@sendgrid.com", :from => email.from, subject => email.subject)
end end
And in your email_processor.rb you would do something like this:
class EmailProcessor def self.process(email) TestMailer.forward_from_incoming_post(email).deliver! end end
— Reply to this email directly or view it on GitHubhttps://github.com/thoughtbot/griddler/issues/22#issuecomment-13436382.
The message forwarding worked, the attachments don't seem to be coming through. I get a "noname" attachment using your code above with the following content:
This is a multi-part message in MIME format...
----
Could you share the original email headers and body?
Not positive how to get that, but I can post my logs. Let me know if that's not what you are looking for. Having looked at them myself, I'm starting to wonder if SendGrid could be labelling my inbound email (from my personal GMail address) as spam!
Feb 13 19:39:53 myapp-app app/web.1: efL2AY 4Wqw==\nMIME-Version: 1.0\nX-Received: by 10.60.26.137 with SMTP id l9mr18647597oeg.17.1360813190518; Wed, 13 Feb 2013 19:39:50 -0800 (PST)\nReceived: by 10.182.80.193 with HTTP; Wed, 13 Feb 2013 19:39:50 -0800 (PST)\nDate: Wed, 13 Feb 2013 20:39:50 -0700\nMessage-ID: \nSubject: Testing email - this is the subject\nFrom: Brandon Parsons \nTo: brandon@myapp.me\nContent-Type: multipart/mixed; boundary=e89a8fb2055ad3967204d5a702d3\n", "dkim"=>"{@gmail.com : fail (body has been altered)}", "to"=>"brandon@myapp.me", "html"=>"
Testing.... this is the body!!\n", "from"=>"Brandon Parsons ", "text"=>"Testing.... this is the body!!\n", "spam_report"=>"Spam detection software, running on the system \"mx5.sendgrid.net\", has\nidentified this incoming email as possible spam. The original message\nhas been attached to this so you can view it (if it isn't spam) or label\nsimilar future email. If you have any questions, see\nthe administrator of that system for details.\n\nContent preview: Testing.... this is the body!! Testing.... this is the body!!\n good evening sir. [...] \n\nContent analysis details: (-0.7 points, 5.0 required)\n\n pts rule name description\n---- ---------------------- --------------------------------------------------\n 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider\n (parsons.brandon[at]gmail.com)\n 0.0 HTML_MESSAGE BODY: HTML included in message\n-0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low\n trust\n [209.85.214.174 listed in list.dnswl.org]\n 0.0 T_MIME_NO_TEXT No text body parts\n\n", "attachment1"=>#@original_filename="test.txt", @content_type="text/plain", @headers="Content-Disposition: form-data; name=\"attachment1\"; filename=\"test.txt\"\r\nContent-Type: text/plain\r\n", @tempfile=#>, "envelope"=>"{\"to\":[\"brandon@myapp.me\"],\"from\":\"parsons.brandon@gmail.com\"}", "attachments"=>"1", "subject"=>"Testing email - this is the subject", "spam_score"=>"-0.688", "attachment-info"=>"{\"attachment1\":{\"filename\":\"test.txt\",\"name\":\"test.txt\",\"charset\":\"US-ASCII\",\"type\":\"text/plain\"}}", "charsets"=>"{\"to\":\"UTF-8\",\"html\":\"ISO-8859-1\",\"subject\":\"UTF-8\",\"from\":\"UTF-8\",\"text\":\"ISO-8859-1\"}", "SPF"=>"pass", "controller"=>"griddler/emails", "action"=>"create"}, @to="brandon", @from="parsons.brandon@gmail.com", @subject="Testing email - this is the subject", @body="Testing.... this is the body!!", @raw_body="Testing.... this is the body!!\n", @attachments=[#@original_filename="test.txt", @content_type="text/plain", @headers="Content-Disposition: form-data; name=\"attachment1\"; filename=\" test.txt\"\r\nContent-Type: text/plain\r\n", @tempfile=#>]>
Feb 13 19:39:53 myapp-app app/web.1: Notifier:ForwardFromIncomingPost:
Feb 13 19:39:53 myapp-app app/web.1: Attachment:
Feb 13 19:39:53 myapp-app app/web.1: #>
Feb 13 19:39:53 myapp-app app/web.1: Content:
Feb 13 19:39:53 myapp-app app/web.1: good evening sir.
Feb 13 19:39:54 myapp-app app/web.1: cache: [POST /email_processor] invalidate, pass
Feb 13 19:39:54 myapp-app heroku/router: at=info method=POST path=/email_processor host=myapp-app.herokuapp.com fwd=74.86.7.102 dyno=web.1 queue=0 wait=0ms connect=1ms service=985ms status=200 bytes=1
@theycallmeswift, @brandonparsons I'm going to go ahead and close this as it hasn't had much activity lately, and it seems that it is not a griddler issue.
@brandonparsons did you solve it? I am doing similar thingy now and I can't figure out how to resend attachments
so I figured out:
attach.each do |attachment|
attachments[attachment.original_filename] = File.read(attachment.tempfile)
end
attach is email.attachments that one gets from EmailProcessor, the code above is how to add attachments in your ActionMailer class
@hovancik Thanks for posting! Super helpful!
Would anyone know how to test with Rspec + FactoryGirl forwarding emails with attachments?
@hovancik This still doesn't work for me. Can you post your whole class? I'm sending out through Mandrill, not sure if that makes a difference.
@rdetert my mailer looks like this:
class MyMailer < ActionMailer::Base
def send_email(from,to,reply,subject,body,attach)
#attach attachments
attach.each do |attachment|
attachments[attachment.original_filename] = File.read(attachment.tempfile)
end
mail( from: from, to: to, reply_to: reply, subject: subject, body: body )
end
end
and then I call it like MyMailer.send_email(email.from,to,reply,email.subject,email.raw_body,email.attachments).deliver
This was Gridller 0.6 or something. But I believe email.attachments is still array in newer Griddler
@hovancik Your solution still works. The problem was with Mandrill and (at least) inline attachments. Switching to Sendgrid works fine. More on the issue can be found here: https://github.com/wingrunr21/griddler-mandrill/issues/15
How would I use
ActionMailer
to just forward this straight along - attachments and all ? Thanks!