#40 smtp-n1442514-40.patch1.14 KBDamienMcKenna
#35 smtp-sending_attachments-1442514-35.patch1.21 KBSkyBuzz
#32 smtp-sending_attachments-1442514-32.patch995 bytesjames.williams
#26 SMTP-1442514-20.patch1.29 KBtetter36
#19 patch.txt1.15 KBmoonberry
#12 smtp-1442514-12.patch1.14 KBtobiasb
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es). View
#8 1442514-8.patch1.05 KBkillua99
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1442514-8.patch. Unable to apply patch. See the log in the details link for more information. View
#1 mimemail-attachment-1442514-1.patch850 bytesmavimo
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch mimemail-attachment-1442514-1.patch. Unable to apply patch. See the log in the details link for more information. View
Members fund testing for the Drupal project. Drupal Association Learn more


mavimo’s picture

Issue tags: +mimemail, +attachment
850 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch mimemail-attachment-1442514-1.patch. Unable to apply patch. See the log in the details link for more information. View

Improved patch to support sending mail using filepath and filecontent.

Into mimemail we can send mail using:

  $params = array(
    'attachments' => array(
      0 => array(
        'filecontent' => '<?xml version="1.0" encoding="UTF-8"? >',
        'filename' => 'test.xml',
        'filemime' => 'text/xml',
      1 => array(
        'filepath' => 'public://test.xml',
        'filename' => 'test.xml',
        'filemime' => 'text/xml',

in accord with mimemail docs.

felixvang’s picture

I'm sorry, I'm new to these stuff. What should I do with this .patch file or where should I add it?

gabrielu’s picture

Status: Active » Reviewed & tested by the community

Thanks for the patch @mavimo , patch #1 worked like a charm for me.

I think this should be ported to the next release.


wundo’s picture

Status: Reviewed & tested by the community » Fixed

Commited, thanks! :)

killua99’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev
Category: feature » support
Status: Fixed » Active

When I send a attachment application/pdf mime file it's apear.

The data could not be saved because the destination /tmp/smtpc856Ac is invalid. This may be caused by improper use of file_save_data() or a missing stream wrapper.

File line 432
version = "7.x-1.0-beta2+3-dev"

killua99’s picture

Ok I can't do a patch cause I'm not using git (sorry) but you can follow this instruction.

Replace all the attachment_new_filename for this.

              $attachment_new_filename = drupal_tempnam('temporary://', 'file');
              $file_path               = file_save_data($attachment, $attachment_new_filename, FILE_EXISTS_RENAME);
              $real_path               = drupal_realpath($file_path->uri);

              if (!$mailer->AddAttachment($real_path, $file_name)) { // , $file_encoding, $filetype);

This is a good use when you creat a tmp name with tmp directory.

tobiasb’s picture

I get this error with mimemail (rule) and smtp

Notice: Undefined index: filename in SmtpMailSystem->mail() (Line 455 of sites/all/modules/contrib/smtp/
Notice: Undefined index: filemime in SmtpMailSystem->mail() (Line 455 of sites/all/modules/contrib/smtp/
killua99’s picture

Status: Active » Needs review
1.05 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1442514-8.patch. Unable to apply patch. See the log in the details link for more information. View

An issue failing with temporary files.

killua99’s picture

Category: support » bug

Change status.

dandaman’s picture

Status: Needs review » Reviewed & tested by the community

The patch in #8 definitely fixed my problem with temporary files from the MIME not saving correctly. Thanks for the patch, killua99!!

wundo’s picture

Status: Reviewed & tested by the community » Fixed

Last patch was committed.

tobiasb’s picture

Status: Fixed » Needs review
1.14 KB
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es). View

Ok my bug is not solved with the latest release.

When you send a html-email via rules to use the attachments, mimemail creates only an array with the filepath key, no filename or something.

rules_action_mimemail -> drupal_mail -> mimemail_mail
(attachment is a string) -> ... -> attachment is an array.

cgdrupalkwk’s picture

Having the same issue as #7. Patch in #12 did not work to solve.

tobiasb’s picture

@cgdrupalkwk then your rule is wrong ;-)

killua99’s picture

Did you test send an attachment without using rules? Because this one seen another kind of issue but with the link of attachment. You use Rules + mimemail + smtp. This issue only use mimemail and smtp. Better to open a new one?

tobiasb’s picture

Ok lets say the patch is a followup. ;-)

chrbak’s picture

I am having a similar problem with the attachment files. I don't use rules only the mimemail with the simplenews module and the error that i am getting is the bellow:

Fatal error: Cannot use object of type stdClass as array in C:\inetpub\wwwroot\sites\all\modules\smtp\ on line 449

The solution i found is to delete the lines 447 to 456 and the problem solved. Now i can send newsletters with the attached files.

chrbak’s picture

I found that at line 449 tries to check a variable that is actualy an oblect like the bellow:

$ Object
    fid = String(4) "2772"
    uid = String(4) "1235"
    filename = String(45) "filename.pdf"
    uri = String(69) "public://(...)/filename.pdf"
    filemime = String(15) "application/pdf"
    filesize = String(6) "372540"
    status = String(1) "1"
    timestamp = String(10) "1365774040"
    rdf_mapping => Array (0)
moonberry’s picture

1.15 KB

I have same problem as #17 with sending attachements, here is a patch for dev version 2013-Mar-17.

MarcusOaten’s picture

For some reason I seem to get 2 (duplicate) attachments when using rules to send attachments, with both the patch and current Dev version.

killua99’s picture

+++ b/	2013-04-29 12:22:37.333324000 +0200
@@ -441,12 +441,14 @@
+        if (!is_object($attachment)) {

Why you need to check is not a object? I mean with an isset or !empty you have done that kind of confirmation.

kolafson’s picture

Had the same issue as #7 and patch in #12 solved it.

jurgenhaas’s picture

Patch #12 works fine for me.

wundo’s picture

Status: Needs review » Fixed

Patch from #12 was committed, thanks ;)

Automatically closed -- issue fixed for 2 weeks with no activity.

tetter36’s picture

Version: 7.x-1.x-dev » 7.x-1.2
Issue summary: View changes
Status: Closed (fixed) » Active
1.29 KB

I couldn't send out emails using SMTP, Simplenews, Mimemail, and Elysia Cron. I was receiving the following error in my logs:

Unexpected termination of cron channel default, aborted. Last job executed: simplenews_cron

I then looked in the apache error log and saw this:
PHP Fatal error: Cannot use object of type stdClass as array in /var/www/financesociety/sites/all/modules/smtp/ on line 469,

Attached is the patch I used to fix the issue. After adding the patch, I didn't get any more errors in the apache log and the emails began sending without the "Unexpected termination of cron channel default, aborted. Last job executed: simplenews_cron" error.

HansKuiters’s picture

Thanks @tetter36, patch #26 works fine for me.

Allerby’s picture

I had a similar problem using Webform2pdf, SMTP and Mimemail. #26 worked for me - however I had to remove the filecontent object reference in the if statement from line 469 and 472. Not a great solution but it did the trick. My final solution looked like this:

    if (isset($message['params']['attachments'])) {
      foreach ($message['params']['attachments'] as $attachment) {
        if (isset($attachment)) {
          $mailer->AddStringAttachment($attachment->filecontent, $attachment->filename, 'base64', $attachment->filemime);
        if (isset($attachment)) {
          $filename = isset($attachment->filename) ? $attachment->filename : basename($attachment->filepath);
          $filemime = isset($attachment->filemime) ? $attachment->filemime : file_get_mimetype($attachment->filepath);
          $mailer->AddAttachment($attachment->filepath, $filename, 'base64', $filemime);
AgentSeo’s picture

Have similar problem #26, after using patch I didn't get any more errors, but email not sending. If I remove attachments and send email next time, both emails will be sent.

DamienMcKenna’s picture

Status: Active » Needs work

Don't forget to set the status to "needs review" when you upload a patch. Also, the patch doesn't apply.

DamienMcKenna’s picture

Version: 7.x-1.2 » 7.x-1.x-dev

The patch needs to be updated to match the Drupal coding standards.

james.williams’s picture

Status: Needs work » Needs review
995 bytes

Patch #26 will only work for file objects. Mimemail supports attachments being added as arrays (when sent through its own hook_mail implementation), but also allows file objects to be sent directly (e.g. when other module's seek to use its mail system).
So if the SMTP module wants to be able to handle them as Mimemail does, it needs to handle both, not just arrays (as currently since #12 was committed), or just objects (as in patch #26).
The attached patch allows either method to be used, by recognising the same properties of either type that Mimemail uses.

BD3’s picture

The patch in #32 is attaching the file in the email for me, but using Webform2PDF it doesn't attach the PDF from Webform2PDF in the email and below is from the error log when it tries to do so.

Notice: Undefined index: exclude_empty in webform_submission_render() (line 645 of /sites/all/modules/webform/includes/
Notice: Undefined property: stdClass::$filepath in SmtpMailSystem->mailWithoutQueue() (line 495 of /sites/all/modules/smtp/

Webform 7.x-4.12
Webform2PDF 7.x-4.0
Mime Mail 7.x-1.0-beta4
Mail System 7.x-2.34
SMTP Authentication Support 7.x-1.3

DamienMcKenna’s picture

Status: Needs review » Needs work

Sounds like it needs a little more work.

SkyBuzz’s picture

I've made the few modifications to the #32 and it is working fine for me.

The webform2pdf provides only filecontent #32 provides attachment keys for the filepath. This modification covers both the cases.

BD3’s picture

Status: Needs work » Needs review

I can confirm that #35 works for me with Webform2PDF PDFs being attached and file uploads from the Webform are also being attached.

Status: Needs review » Needs work

The last submitted patch, 35: smtp-sending_attachments-1442514-35.patch, failed testing.

truman_ru’s picture

#35 resolved my problem with attachments in Webform

  • wundo committed 364afc7 on 7.x-2.x
    Issue #1442514 by tobiasb: Sending attachments using modules smtp and...
  • wundo committed 542f920 on 7.x-2.x
    Issue #1442514 by lavisrap, mavimo, gabrielu: Fixes sending attachments...
  • wundo committed d37eabe on 7.x-2.x
    Issue #1442514 by killua99: Fixes attachments of temporary files
  • wundo committed ec93c27 on 7.x-2.x
    Issue #1442514 by wundo: Fixing indentation added by last patch
DamienMcKenna’s picture

Status: Needs work » Needs review
1.14 KB

Rerolled, and I fixed the errant whitespace and minor coding standards issues.

jayroberts’s picture

The patch in #40 resolved the issue for us when using Webform2PDF with SMTP Authentication, MailSystem, MimeMail and attached files in Webform email notifications. Attachments are included properly in all cases.

sam-elayyoub’s picture

Just to make life easier try to build a simple module calling your file and attach it to any email you want to send

* Get your file info 
function YOURMODULE_attach($fid, $language){
return file_load($fid);
 * Send an e-mail.
function YOURMODULE_mail($fid){

$key = 'YOURMODULE_mail';
$from = variable_get('site_mail', '');
$to = 'TEST@TO_WHO.COM';
$file = YOURMODULE_attach($fid);

$msg = array(
      'subject' => 'YOUR SUBJECT',
      'message' => 'YOUR MESSAGE',
      'files' => array(),
          $f1 = new stdClass();
          $f1->uri  = $file->uri;
          $f1->filename  = $file->filename;
          $f1->filemime  = $file->filemime;
          $f1->type  = $file->type;
$msg[files][] = $f1;
  $msg = array(
      'subject' => 'YOUR SUBJECT',
      'message' => 'YOUR MESSAGE',

// add watchdog() to make sure you debug everything

watchdog('YOURMODULE', '<pre>' . print_r($msg, TRUE) . '</pre>', array(), WATCHDOG_NOTICE, NULL);

drupal_mail('YOURMODULE', $key, $to, $language, $msg, $from, TRUE);


hope this module would solve any problem with the attachments and SWIFTMail or MIMEMail


Johan den Hollander’s picture

#40 works for me. I applied this patch to the lastest dev.
7.x-2.x-dev - 2016-Dec-26

Using this with Simplenews including pdf attachment.