I got the module working in test mode. The mail is sent to the test address.
When I switch off the test mode, the mails are not sent. I get no error message in Drupal, but I do not receive the mails. I use the same email as for the test mode.

Can someone please guide me through this?

I am using a customized node type which contains a name (CCK text) and email field (CCK email).

Comments

Firewolf’s picture

It seems it has something to do with the email address of "sender" and "receiver" which can not be the same. I tested with another email and it is working now.

But I have another problem now. The attachment which I added to the newsletter is not sent. Is it possible to add attachments to the mail?

somebodysysop’s picture

Title: Only working in test mode » Attach files to newsletters?

Don't know if it can be done. Need to post the question in mimemail issues since that's the module used to send views_mail emails.

somebodysysop’s picture

Category: bug » feature
Firewolf’s picture

Looks like somebody already posted a question in the mimemail project ;) Thanks again for the help.

For the records: http://drupal.org/node/186049

Firewolf’s picture

Actually it required a change in the Views Mail module.

I changed

if ($result = mimemail($sender, $recipient, $subject, $message)) {

to

$plaintext=null; $headers=array(); $text=null;
if ($result = mimemail($sender, $recipient, $subject, $message, $plaintext, $headers, $text ,$attachments)) {

and the attachments were added to the mail.
I had to change the mimemail call twice (line 893 & 908).

somebodysysop’s picture

If you are able to successfully attach files using views mail, could you please explain what else you did.

I made the changes you gave above, but get this error when attempting to send newsletter with file attachments:

* warning: Invalid argument supplied for foreach() in /var/www/html/websites/drupal/sc/modules/mimemail/mimemail.inc on line 365.
* warning: Invalid argument supplied for foreach() in /var/www/html/websites/drupal/sc/modules/mimemail/mimemail.inc on line 365.

Thanks!

oadaeh’s picture

The $attachments variable in the mimemail() function is an array of arrays like so:

Array
(
    [0] => Array
        (
            [filepath] => /tmp/phpxc07Sk
            [filemime] => image/png
        )
    [1] => Array
        (
            [filepath] => /tmp/php242VYM
            [filemime] => image/png
        )
)

Where each internal array represents a separate file.

I'm working on a patch that will hopefully introduce a third element, but that isn't there yet.

somebodysysop’s picture

Can someone please explain how you get this to work?

oadaeh’s picture

Here's a couple of snippets of what I did in Mass Contact. You can scan the mass_contact_mail_page_submit() function for all the gory details.

  if ($_FILES['files']['size']['attachment'] > 0) {
    if (module_exists('mimemail') && variable_get('mimemail_alter', 0) == 1) {
      $message_attachment = array(
        array(
          'filepath' => $_FILES['files']['tmp_name']['attachment'],
          'filename' => $_FILES['files']['name']['attachment'],
          'filemime' => $_FILES['files']['type']['attachment'],
        )
      );
    }
    else {
      $message_attachment  = '--'. $uid ."\n";
      $message_attachment .= 'Content-Type: '. $_FILES['files']['type']['attachment'] .'; name="'. basename($_FILES['files']['name']['attachment']) ."\"\n";
      $message_attachment .= "Content-Transfer-Encoding: base64\n";
      $message_attachment .= 'Content-Disposition: attachment; filename="'. basename($_FILES['files']['name']['attachment']) ."\"\n\n";
      $message_attachment .= chunk_split(base64_encode(file_get_contents($_FILES['files']['tmp_name']['attachment'])));
      $message_attachment .= "\n\n--". $uid ."--\n\n";

      $message[]           = $message_attachment;
    }
  }

And then later on:

          if (module_exists('mimemail') && variable_get('mimemail_alter', 0) == 1) {
            $success = mimemail($from, $to, $subject, $body, NULL, $headers, NULL, $message_attachment);
          }
          else {
            $success = drupal_mail('mass-contact-page-mail', $to, $subject, $body, $from, $headers);
          }

Keep in mind that the "'filename' => $_FILES['files']['name']['attachment']," line in the first snippet requires a patch to Mime Mail that I created here: http://drupal.org/node/223176. If you don't want to apply the patch, then just leave out that line.

Also, Mass Contact currently only allows one attachment. If Views Mail allows more than one, then just keep adding to the array ($message_attachment in the snippets above).

somebodysysop’s picture

Status: Active » Needs review

Now using Simplenews to send emails, so they have a file attachment solution. The files aren't actually attached (they are links back to the site), but something's better than nothing.

http://drupal.org/files/issues/views_mail.module.5.x-2.0.patch

somebodysysop’s picture

Status: Needs review » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

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