Attach file using CMail in Dolibarr

I made cronjob for sending mail with attachment but it send e-mail without attachment, although there is an icon for attachment but it is empty. How can I solve this problem.

I had to require the CMail class:
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';

And then I went to send the mail I made sure to define $filepath and $filename as arrays.

$filepath = array();
$filename = array();
$mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext);

It is hard for me to tell what you are doing to “code-wise” for this cronjob without actually seeing some code on how you are sending emails/

thank you for answer here is my code it would be nice to solve my problem.

This class should make csv file out of sql data and send an e-mail with attachment.
It make csv send email with attchment icon without csv file.

I am reviewing your code. I collected a log on an email using a CSV file I used to send to an internal user to see what the system logs in the CMailFile.class.php file for the _construct function.

I don’t think it has anything to do with your mimetype being array("text/csv"); as I believe that is the correct setting.

Maybe it is the filepath as I do not see the filename in the path - array("C:\\xampp\\htdocs\\dolibarr\\htdocs\\cron");

These are my findings:


filename_list: Array
    [0] => /var/www/path/temp/new7.csv


mimetype_list: Array
    [0] => application/octet-stream
    [1] => application/


mimefilename_list: Array
    [0] => new7.csv

If none of this helps, try setting up a log in the CMailFile.class.php file _construct function to what values are being sent to the constructor for filename_list, mimetype_list, and mimefilename_list. Then maybe we can go from there.

thank you!!
the problem was as you said there was no filename in the path.

Awesome! Glad you are on your way this cron.