Posted by skanarakis on February 17, 2012 at 12:17pm
Hello all,
I would like to know if we have the capability in Drupal 7 to have the Rules framework set up a "Send Email" action and include in that email a file field from a custom content type we have in our website.
For example, once a user has created a specific content type node (having a file attachment), I would like to have Rules send an email including the file attachment inside it (along with other information from the node itself).
Is there any way to configure it via the Rules UI (and possibly other modules) or somenone has to code a new module?
Thanks
Stavros
Comments
Of course you can do it. Use
Of course you can do it. Use Mime Mail module and you'll get 'send html mail' action.
Thans for the quick answer !
Hi artt and thanks for quickly answering that.
I guess that the MIME MAIL module will help me with the attachement field.
For incorporating other non-file fields of that content type in my email (like Body, Title, tags etc), am I going to use the Tokens module?
Is this field "fetching" possible with Tokens?
Thanks
Stavros
you can send attachments
you can send attachments since mime mail module support html emails and attachments.
And, you can attach a file filed from a node, see #6 in http://drupal.org/node/1431572.
Art
So, it needs some minimal coding, right?
Hi Art,
So I guess that I need to do some minimal coding inside the attachement value field as shown inside the comment #6 in the link you gave me.
This is for the file field (the attachement in the email).
What about other non-file fields (node title, node description, node tags etc) that need to be a part of the email body part?
Is there a need to code for them too?
Or I can have it via configuration (fetch their field values through tokens in some way and put them under the email body part)?
I really appreciate your help
Stavros
Hi Stavros, You need to write
Hi Stavros,
You need to write a snippet to use a file field as an attachment. This is because right now mime mail has a bug when using a file field. If you want to attach a fixed file in your web's directory, you just input the path in the email's attachment field.
You can use tokens to represent other data / field in a node. No need to write any snippet.
Art
Thanks artt ! You are really
Thanks artt !
You are really helpful to me.
I figured out how to use tokens in order to get other non-file fields.
And I understand what I have to do to send attachments as well ( I will just have to figure out the code itself ! ).
If I have a multiple value file field, is it still possible to send more than one attachments (each attachment representing one of the multiple file-field items) by using a foreach statement in the code snippet?
Have you actually tried it?
Thanks
Stavros
Nope, I've never tried it.
Nope, I've never tried it. Theoretically I think we can attach with a multiple value file field.
Art
HTML mail module?
Is there a way to do the same with HTML mail module? I can send HTML mails from rules with that module but don't find a way to add a attachment.
for fields attechment
You can use in Rule ACTION fields and add the Send HTML e-mail,in attechment 'value'
fields write the php code:
<?php$language = field_language('node', $node, 'field_upload_resume');
foreach($node->field_upload_resume[$language] as $file) {
echo drupal_realpath(file_load($file['fid'])->uri);
}
?>
Gautam Kumar
More fields possible
Is it possible to load more field into the attachment..
I have more upload fields, and want to send them all as attachment.
Is this possible?
Can't get attachments to work no matter what...
I'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.
<?phpforeach($registration->field_anon_resume['und'] as $file) {
// echo drupal_realpath(file_load($file['fid'])->uri); // returns /var/www/acme/sites/default/files_private/file.txt
// echo file_load($file['fid'])->uri; // returns private://file.txt
echo file_create_url(file_load($file['fid'])->uri); // returns http://website.com/system/files/file.txt
echo ("\n");
}
?>
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.
Maybe this will help
Hello. I had the same problem. Mime mail was misconfigured.
http://webwash.net/tutorials/how-send-html-emails-drupal-7-using-rules
With this "code" in the body field of my mail. Not the attachment field...
[node:body]<a href="[node:field-files:0:file:url]">[node:field-files:0:description]</a>
So, I have a link to my file and a tiny tiny email ;-)
Use
Hello defconjuan,
Try "echo("\r\n");", probably you use windows as the dev server ;)