Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Good day,
I need some documentation to send a mail with attachments from Rules, cause i understood that i should provide the [mime-type]:[path] in the area under the attachments label in Rules, but i only see this information [candidature:field_cand_cv] in the Replacement patterns for my content-type candidature. so i dont have the [mime-type] apparently.
Could anyone help me or provide me some documentations.
Comment | File | Size | Author |
---|
Comments
Comment #1
sgabe CreditAttribution: sgabe commentedWhere do you see that you should provide the MIME-type? That is no longer needed in the 7.x-1.x branch, see #1305824: Leave MIME type and use only path to specify an attachment.
Comment #2
sletis CreditAttribution: sletis commentedthx for answering,
i just tried to send an attachment directly with [candidature:field_cand_cv] which is a File field.
I didnt get any attachment in the mail i received, i tried it like that "[candidature:field_cand_cv]" and '[candidature:field_cand_cv]'
i also print the [candidature:field_cand_cv] in a system message it s providing me the link to file: http://www.mywebsite.fr/sites/default/files/cvs/mocv_2.docx
Did i miss doing something?
ps: sorry for my bad english.
Comment #3
sgabe CreditAttribution: sgabe commentedYou need a relative path, not an absolute URL.
Comment #4
sletis CreditAttribution: sletis commentedah ok thx! last question how could i make this path beeing relative?
it s the only replacement pattern to my file i have access to!
Comment #5
lavisrap CreditAttribution: lavisrap commentedI have similar problem. For testing I used the relative path files/1.pdf and there is such a file in /sites/default/files, but still I receive the email without attachment.
Comment #6
SilviuChingaru CreditAttribution: SilviuChingaru commentedI use a code like this in "Attachments" value field:
and is working fine.
Comment #7
s1work CreditAttribution: s1work commentedFor the life of me I cannot figure out how to get Rules and mime mail to send out the attachment from my file field on my content type. I've tried everything, and nothing works. fiftyz I've tried your solution to no avail. I'd really love to get this working. I appreciate anyone's help in resolving this.
Comment #8
SilviuChingaru CreditAttribution: SilviuChingaru commented@s1work plase dpm node and export your rule and post them here.
Comment #9
narcisgirona CreditAttribution: narcisgirona commentedSame here!! Anyone managed to get file attachments working?
Comment #10
narcisgirona CreditAttribution: narcisgirona commentedgetting closer.. i manage to sent via absolute path and email with attachments.
on the attachment value field of rules: (make sure to put "/" on front of the path) /sites/default/files/file_attached.jpg (then you just have to have a copy of that file on this path). It works for me this way.
The problem is that if i wanna attach "dynamic" files via field_image where the user uploaded that file is when gets tricky.. i guess i should do something like:
/sites/default/files/[node:field_image] or /sites/default/files/[node:field_image:path]..
but still can't find the token or way which provides me the path or name of the user uploaded file throu field_image.
Anyone can help?
Thanks again guys
Comment #11
narcisgirona CreditAttribution: narcisgirona commenteddid you managed to make it work?
Comment #12
SilviuChingaru CreditAttribution: SilviuChingaru commented#6 is working fine on a production site. Did you try that code? If so and is not working post it here and I'll try to help you.
Comment #13
narcisgirona CreditAttribution: narcisgirona commentedTo be honest have no idea where i have to implement that:
as well do i have to adapt it somehow?
Comment #14
narcisgirona CreditAttribution: narcisgirona commentedI found out that [node:field_image] is "printing" the url of the images: http://www.mysite.com/sites/default/files/intercanvis/logotype5.png
and if i just cut away the "domain" it works: /sites/default/files/intercanvis/logotype5.png
so i guess now i have to figure out how to adapt it somehow.
Any suggestions?
Comment #15
SilviuChingaru CreditAttribution: SilviuChingaru commentedYou have to put that in the Attachment field.
Change 'field_document_pdf' with your field name and also $node ->field_document_pdf.
Your code should look like this:
Comment #16
narcisgirona CreditAttribution: narcisgirona commentedi did that but still not working
Comment #17
narcisgirona CreditAttribution: narcisgirona commentedIt works!
Had php module off.. my bad!!
THANKS fiftyz and everyone!!
Comment #18
SilviuChingaru CreditAttribution: SilviuChingaru commentedYou're welcome. Don't forget to give back to community and help others with your knowledge ;-)
Comment #19
SilviuChingaru CreditAttribution: SilviuChingaru commentedComment #20
botrisYou can just use the URI, no need for drupal_realpath & file_load.
Also according to the drupal_realpath API page
This should work:
I have a field with one file max and no languages so I use:
Comment #21
rhrueda CreditAttribution: rhrueda commentedAs the Attachments field says:
don´t forget to add a new line if you want to send more than one attachment.
In my case I have nodes with several pdf documents each. This is what worked for me:
Comment #22
bsandor CreditAttribution: bsandor commentedWhat php module is this guys please? ( #17 )
Comment #23
raamsri14 CreditAttribution: raamsri14 commentedi didn't see any attachment field in rules. how to get the attachment field?
Comment #24
jday CreditAttribution: jday commented#21 works for me, Thanks rhrueda!!
Comment #25
Valdars CreditAttribution: Valdars commentedHad similar problem and even code samples here didn't help me. So looked around in Mimemail module code and discovered that it can actually use Drupal uris for attachments, eg public://path/file.ext.
So what worked for me was
[node:field-filefield:file:path]
.PS: Rules direct input thought that file field "file" property does not have "path" property altough it really does.
Comment #26
spire CreditAttribution: spire commentedWhere abouts do you place this code? is it a custom field? Someone said that it was in the attachment field, where abouts is that?
sorry for so many questions, im just unsure about what with the code as there is no clear answer of where it goes.
Comment #27
gthing CreditAttribution: gthing commentedWhere is the attachment field? Would love an answer for #23 and #26. Apparently some people have been able to find such a field. Help??
Nevermind, I found it. You have to create a new html email with attachment instead of a regular email to users. It's in the menu when you create the action in rules.
Comment #28
Sam MooreWhat worked for me was putting the following in the Attachments field of the "Send HTML Email" :
My field is called "field_attach_file" (that's its machine name).
I allow multiple file uploads, so I have to walk the array field_attach_file['und'] in order to visit each attachment. (They're referenced as field_attach_file['und'][0], field_attach_file['und'][1], and so forth - but the foreach takes care of that).
These arrays don't have an nid key, nor a uri that I can dereference, but they do have fid's - each one is just a number (corresponding to an entry in the /media hierarchy).
I can get to the files via a browser using /media/[fid] - but that won't do for attachments.
So now I have to get the real path of the file from that fid, so as to attach it.
That's where the drupal_realpath(file_load($file['fid'])->uri) comes in - it gets the filesystem path of the asset and actually attaches it to the email.
Comment #29
andros CreditAttribution: andros commented#25 worked for me. I think this is the way to go, but the rules selector and tokens should be aware of the path property and it should be explained in the token area.
I don't see any option for "path" in the direct select mode. So the function is there but is it not exposed to the user anywhere, I think this should be fixed!
Comment #30
tinohuda CreditAttribution: tinohuda commented#26 and the similar only work for 1 file.
i attached some files and those code NOT WORKING.
anyone can help, plz. thanks before.
Comment #31
asimag CreditAttribution: asimag commentedOn Drupal 7 I am using Latest Dev of SMTP and Mime Mail. You will also need to configure SMTP and MIme Mail to work coherently. See the section Alternative Approach at: https://drupal.org/node/1200142
The following path in rules attachment input box worked perfectly:
sites/default/files/abc.png
Don't put / in front of sites folder.
Although it will send duplicate attachments. To fix that follow: https://drupal.org/node/1988482
Comment #32
michaelgiaimo CreditAttribution: michaelgiaimo commentedThis worked for me. My field name is "field_white_paper." I hard-coded the directory the attachments live in, then followed it with this node token:
[node:field-white-paper:file:name]
Note the underscores have been changed to dashes. So the attachment field looks like:
/sites/default/files/white-papers/[node:field-white-paper:file:name]
Comment #33
AnybodyHave a look here, if it's a problem with a newer version of mimemail.module than alpha2: #1389504: Documentation for sending emails with attachments
Comment #34
bennett_pr CreditAttribution: bennett_pr commentedIf, on the off chance, you're also trying to do this using EntityForms, this structure worked for me in the 'Attachments' textarea for the rule:
To attach files:
sites/default/files/[entityform:FORM_FIELD_NAME:file:name]
To attach images:
[entityform:FORM_FIELD_NAME]
Comment #35
lindsay.wils CreditAttribution: lindsay.wils commentedIm trying to get this working with a private file and have tried every option here to no avail! Has anyone managed to get this working with private files? Or im just doing something else wrong.... please help anyone :)
Comment #36
defconjuan CreditAttribution: defconjuan commentedI've tried the following formats in the attachment field and none work:
I used the following code in the message body before adding it to the attachments field; so that I could see what would be echoed when the same code was used in the attachment field.
Nothing. Absolutely nothing and no error log messages. The email comes through fine, but there are no attachments. I even tried putting a sample file in the sites/default/files (eg. public file system) and used manual entries replicating all the file patterns above and no attachments went through.
Any current advice on this would be appreciated because not being able to send attachments with Rules and MimeMail HTMLMail is a blocker.
Comment #38
defconjuan CreditAttribution: defconjuan commentedComment #39
defconjuan CreditAttribution: defconjuan commentedComment #40
sgabe CreditAttribution: sgabe commentedCurrently by default you should be able to use files located in the public file system (e.g. sites/default/files).
With the "Send arbitrary files" permission you should be able to send files located outside the public file system. Note that this means every other locations, your private file system (e.g. /var/private) and even your settings.php!
Comment #41
sgabe CreditAttribution: sgabe commentedAlso running Drupal in a subfolder may be an issue as per #2290107: URLs in body of email print incorrectly when Drupal $base_url is in domain subfolder.
Comment #42
defconjuan CreditAttribution: defconjuan commentedWe are not running Drupal in a subfolder, but the:
permission may be the issue. But it sounds like this is a security issue. For example, let's say you have an anonymous job application page where someone can submit their resume; in this instance you'd have to give the "Send arbitrary files" permission to "Anonymous" users. Doesn't that open huge security holes?
Comment #43
my-family CreditAttribution: my-family commented@sgabe: according to my testing, the new version of Mime Mail is not able to send files outside the drupal root. However, the old version (7.x-1.0-alpha1+20-dev) was, without problems.
The path is the same:
home/domains/[DOMAIN]/[PRIVATE-FOLDER]/[SUBFOLDERS(S)]/test.doc
The permissions settings ("Send arbitrary files") don't make any difference.
It is absolutely necessary for us to send private attachments. What would you recommend? Is it possible to stay with the old version? I see "security update" in the modules updates list but no security issue for Mime Mail in that period...
Thank you in advance for your advice.
Comment #44
my-family CreditAttribution: my-family commented... and the latest -dev version (7.x-1.0-beta3+13-dev) does at least something: it sends an attachment.dat file with the file address:
https://[SUBDOMAIN]/home/domains/[DOMAIN]/[PRIVATE FOLDER]/[SUBFOLDER(S)]/test.doc
which is wrong.
When the right address is hardcoded via PHP, it sends the attachment.dat file with the right address:
https://[SUBDOMAIN]/system/files/[SUBFOLDER(S)]/test.doc
However, it does not send the attachment.
Comment #45
defconjuan CreditAttribution: defconjuan commentedAs a work-around, we ended up creating a function that works with the "Send HTML e-mail" rule action, attachments field:
And in the "attachments" field of the "Send HTML e-mail" rule action:
In the 2nd code block, you would replace $registration->field_resume['und'][0]['fid'] with the token for your entity and file field.
Comment #46
my-family CreditAttribution: my-family commented@vtldevelops: do you have the private file path outside (above) the drupal root?
Comment #47
defconjuan CreditAttribution: defconjuan commentedNope, it's /sites/default/files_private.
Comment #48
skorzh#25 works for me, thanks a lot!
Comment #49
Nick Bell CreditAttribution: Nick Bell as a volunteer commentedYou can enable multiple attachments simply by appending a newline after each file:
Comment #50
Cyclonecode CreditAttribution: Cyclonecode commented#45 work fine for me using Drupal 7-36 and Mime Mail 7.x-1.0-beta3 in order to attach private files.
Comment #51
presleyd CreditAttribution: presleyd commentedIf your private files are under the web root they aren't private. /sites/default/whatever is NOT a private file.
Comment #52
Anonymous (not verified) CreditAttribution: Anonymous as a volunteer commentedThe following code should work properly. The file uri is enough however, "\n" needs to be replaced with "\r\n".
This worked for me with an Acquia Drupal installation running Drupal 7.34 along with Mail System 7.x-2.34 and Mime Mail 7.x-1.0-beta3.
Comment #53
idea_vasil CreditAttribution: idea_vasil commented#26 worked for me. Tnx @spire
Comment #54
penone CreditAttribution: penone commentedAm trying to use #25
[node:field-filefield:file:path]
from a field in a webform that is nested in a fieldset but can't figure out what the correct machine name would be.For my example the input html is:
<input class="form-control form-file" type="file" id="edit-submitted-machinery-list-upload-file-0-upload" name="files[submitted_machinery_list_upload_file_0]" size="22">
Comment #55
mlodymicky CreditAttribution: mlodymicky commentedFor testing I used the path: sites/default/webform/files/1.jpg and it works. But I need recieve uploaded file by users. I have file field to upload different file types in my webform module. I'm neewbe so tell me how to get it work.
Comment #56
delxpez CreditAttribution: delxpez commented#25 worked for me.
Comment #57
nimek CreditAttribution: nimek commented[node:field-filefield:0:file:path]
[node:field-filefield:1:file:path]
[node:field-filefield:2:file:path]
Worked for me in multivalue field case
Comment #58
nerdcore CreditAttribution: nerdcore at OpenConcept Consulting Inc. commentedI'm using Mime Mail 7.x-1.0-beta3 with Drupal 7.57 and unable to attach private files.
Marking this Major, as using the public files directory is not an option in my case; The attachment required is a Commerce Invoice and should never be seen by anyone other than the intended recipient.
Using public://filename.pdf works fine, but using private://filename.pdf generates the PDF and Mime Mail fails to attach it.
I'll try working through reply #45 but would be great to see this fixed in the module itself.
Comment #59
nerdcore CreditAttribution: nerdcore at OpenConcept Consulting Inc. commentedFor my purposes the patch provided by #2624516: Attach non-public files resolves this issue in a way which addresses my security concerns (anonymous should probably not be granted broad access to the entire private files directory) ad allows the Rule firing as Anonymous to attach from locations specified within the MIME Mail module configuration for the site.
If that patch is committed, then perhaps this issue can be marked Closed (Duplicate).
Comment #60
TR CreditAttribution: TR commentedClosing this again ... the original poster's support question was answered 6 years ago and the issue was closed at that point.
Subsequent posts are all over the place talking about different problems with different versions of Rules.
Some of the more recent posts are about attaching private files - that is a feature request which is being addressed in #2624516: Attach non-public files.
If you have problems sending file attachments via the Rules action provided by Mime Mail, then please do not re-open this issue. First, READ this issue to see if any of the above applies to you, and if nothing here helps then open a NEW support request with details about what you are trying to do and what is happening.
Comment #61
vpa24 CreditAttribution: vpa24 commentedHow to send multiple images file in Rule module?
Comment #62
lubwn CreditAttribution: lubwn commented#57 worked for me.
Comment #63
alpha-1 CreditAttribution: alpha-1 commentedHi,
I am using rules Version: 7.x-2.13 when I send a file as attachment greater than 8MB it fails. max php upload and post_max_size is 20MB
what am I missing?
Drupal:7.87
Thanks
Comment #64
jaspm2004 CreditAttribution: jaspm2004 commented#28 working for me
#31 thanks! I was having the duplicate issue too