Closed (fixed)
Project:
Mime Mail
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
6 Oct 2010 at 02:49 UTC
Updated:
14 Apr 2011 at 16:21 UTC
Jump to comment: Most recent file
I am generating content within my code, and I want to email that content as an attachment. Currently this cannot be done except by creating a temporary file. This patch allows me to pass the content directly to mimemail() like this:
mimemail('to@to.com', from@from.com', 'Subject', 'Body', NULL, array(), NULL,
array(array(
'contents' => 'asdfadsfawer',
'filename' => 'gibberish.txt',
'filemime' => 'text/plain'
)));
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | mimemail.932962_04.patch | 4.89 KB | sgabe |
| #6 | mimemail-contents-attach.patch | 1.9 KB | ob3ron |
| #4 | contents.patch | 1.73 KB | ezheidtmann |
| mimemail.patch | 1 KB | ezheidtmann |
Comments
Comment #1
ezheidtmann commentedPatch applies against new development version without modification.
Comment #2
sgabe commentedI think this should be done by _mimemail_file(). We can add a $content parameter then it will do the rest. Would you mind modify your patch in that way?
Comment #3
ob3ron commentedI looked into rewriting this patch as requested by sgabe, but with all due respect it seems to me that it makes more sense the way it was originally written by clydefrog. Can you explain the reasoning behind wanting this to be done by _mimemail_file()? If the attachment is a string rather than a file then there isn't really any reason to call _mimemail_file, and as far as I can tell it would take more code to include it there.
For my implementation, the one change I made from the submitted patch was:
Comment #4
ezheidtmann commentedI like sgabe's suggestion, actually. It puts the code with similar code. I made this patch, but haven't had a chance to test it yet.
Comment #5
ob3ron commentedQuick testing -- you need the
elseif ($content)clause before theelseif ($url)clause. For my use case, I need to pass a path to mimemail -- I am attaching a PDF created by a view passed through the print_pdf module, and the path provides the view that is being converted.Comment #6
ob3ron commentedThe attached patch works for me.
Comment #7
sgabe commentedI think we can do a bit better than that.
@arvana: Why would you need the path? You just need to set the "filecontent". I'm doing something like this and it works fine. Of course this is a dirty hack for me to be able to test this patch.
Comment #8
ob3ron commentedThanks to both of you for giving this issue your kind attention.
@sgabe: In my use case, I am attaching a PDF that is converted from a View. So I'm using print_pdf both to create the $html and the PDF attachment. I am definitely not a real programmer though, especially in Drupal, so I'd be happy to hear if there's a better way to do what I want. Here's my code -- 'ticket' is the View of the content I'm attaching:
Comment #9
sgabe commentedThat's okay, what I don't understand is why the patch in #7 would not work for you?
Comment #10
ob3ron commentedIt doesn't work because I am passing both a $url and $content through _mimemail_file -- it may not be the most common use case, but anyone who wants to attach a PDF created by the print module is going to have to do that. So for this use, it needs to check for $content before it does other things with $url. :)
Comment #11
sgabe commentedI still don't understand why would you need to pass the $url to _mimemail_file() when the attachment is created by it's content.? :)
Furthermore, in #8 you didn't set the filepath for the attachment, hence the $url will be NULL in _mimemail_file(). So the patch in #7 should work for you.
Comment #12
ob3ron commentedHaha well it DOESN'T work, whereas if I put the $content clause before the $url clause it does. Maybe my diagnosis of WHY it doesn't work is wrong. I will investigate further.
Comment #13
naringas commented(subscribe)
I'm interested in this... my module needs to send generated PDFs (using TCPDF) from a rule
Comment #14
ezheidtmann commentedsgabe, your latest patch looks great. And it is working well in my use case:
Is it now ready to be rolled into the official release?
Comment #15
sgabe commentedIt looks ready to me, I would like to commit some issues next week. This one included, if arvana can't tell us why would this not work for him.
Comment #16
ob3ron commentedSorry it took me a while to get back here -- I finally figured out the error. It was my fault; I missed the variable name-change from $attachments[x]['contents'] to $attachments[x]['filecontent'].
So this gets the go-ahead from me to commit. :)
Comment #17
sgabe commentedThanks for your feedback, arvana. I guess this can be marked as RTBC.
Comment #18
sgabe commentedCommitted to 6.x-1.x, but needs to be ported to 7.x.
Comment #19
sgabe commentedNow committed to both branches.