Users like me who have problems with their host about mail() function should benefit a lot from a bond between smtp module and mimemail module.

Further than this phrase I cannot say how it can be done, but mimemail knows how to send HTML mails and SMTP can help to bypass mail() function...

How does this sound?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Allie Micka’s picture

Project: Mime Mail » SMTP Authentication Support
Version: 7.x-1.x-dev » 5.x-1.x-dev

I'm kicking this over to the SMTP module.

Mime Mail was written to handle such a bond, but the SMTP module must implement it correctly.

To make this work, the smtp module must implement a mailengine hook. Copy the mimemail_mailengine function to smtp_mailengine and change the 'send' operation to use SMTP rather than mail().

Then, instead over overwriting the smtp_library variable, let mimemail handle things. On Mime mail's settings page, select the smtp mailengine instead of the default one.

norrab2’s picture

Isn't anyone going to look into this?

LukeLast’s picture

I'm sure it would be great, I just can't work on it right now.

bennybobw’s picture

I'm working on this. I don't know how long it will take. I'm still learning how all this works. Thanks.

-bennybobw

mike stewart’s picture

Looking forward to it. Hopefully with better compatability than current SMTP module (see: http://drupal.org/node/126147#comment-226970)

vildmule’s picture

I have added this line to check if body contains html

else if (strtolower($key) == 'content-type' and strtolower($value) == 'text/html') {
      $mail->IsHTML(TRUE);
    }

to

else if (strtolower($key) == 'content-type' and strtolower($value) == 'text/html') {
      $mail->IsHTML(TRUE);
    }
	else if(preg_match("/([\<])([^\>]{1,})*([\>])/i", $body)) { 
      $mail->IsHTML(TRUE);
    } 

Some modules do not send if its html or if you use Tinymce

if any html in body it will change headers to Html

Cheers from Denmark (europe)

ouzo’s picture

@Allie:

I dont really understand what I must do to get it on work. Can you please describe it in detail witch changes I must do .

mac_perlinski’s picture

FileSize
20.93 KB

Hi there,

i'm not really having so much time for going through the this module but we were having problem with mediatemple mail() so we had to develop custom solution (more than 12k mails in the database).

This module is tend to tie simplenews, mimemail and smtp at least we are using it in this configuration with external virtual host which is used as smtp server.

I m attaching changed smtp.module (there is also bounced managment for simplenews in this module and i have no time for cleaning this up right now but if there will be more feedback on that i ll find some time to make it official module).

So enjoy and give me some feedback if you feel like this changed version of smtp module solved your problem and if you think we schould prepare it as a standalone module.

Kindest regards,
Maciej Perlinski
maciej.perlinski@meant4.com
http://www.meant4.pl Web Studio

nrasmus’s picture

subscribing - your smtp.tgz did not seem to do the trick for me. I noticed no install, but you've added fields, what sql fields must be created?

I would be thrilled if this integration was achieved.

oadaeh’s picture

Title: A bond between mimemail and smtp module? » Mime Mail intergration: A bond between mimemail and smtp module?

Organizing the issue queue.

jsm174’s picture

FileSize
13.6 KB

Attached is a patch will allow SMTP module and Mime Mail work together.

The SMTP module will continue to work as always if the Mime Mail module is not enabled.

I have test sending HTML, Plain Text, and Attachments successfully.

I think there maybe an issue with the From and Reply-To when calling mimemail().

Hopefully we can figure that out.

-- Jason

melon’s picture

Status: Active » Needs work

Jason, thank you for your patch, it works like a charm.

However, there is an issue with the From and Reply-To headers when it's called from mimemail.
The problem is, that mimemail sends the $sender variable already constructed, like this: "Name" <name@domain.tld>

You will have to rebuild the 'FromName' and 'From' values from $sender in the _drupal_mail_wrapper() function. I came up with this quick-n-dirty solution and it seems to work for me when sending mails via simplenews:

   $from_name = preg_replace("/\"(.*)\"(.*)/i","$1",$from); // It gives: Name
   $from = preg_replace("/(.*)\<(.*)\>/i","$2",$from); // It gives: name@domain.tld

Please feel free to modify and adapt the above, I'm not a php coder.

jsm174’s picture

Thanks for testing out the patch!

I thought there would be an issue with from and reply-to. I tested with the contact form and some quick calls to mimemail().

I just installed SimpleNews to try out. I'm still working through it. For some reason, the From header is just the name of my site, with no email address. The configuration for the newsletters does have a separate name and email address.

-- Jason

melon’s picture

The From header doesn't just contain the name of the site, with no email address, but the name of the site + email address, like "Name" <name@domain.tld>
That's why it should be processed by a regex which separates the name and the address.

One more essential issue with your patch, Jason: it only works when mimemail is set to all outgoing messages. Without this option, it fails and says no drupal_mail_wrapper function is present. I suppose this is because you detect the presence of mimemail with module_exists(). I suggest using some smarter code which would be able to determine whether smtp.module is called by mimemail or not.

jsm174’s picture

I understand what you are saying with the From header. I dumped out the headers during the send with SimpleNews, and my site was definitely not including the email address. I may have messed something up on my end during writing the patch, so I'm going to put fresh versions of mimemail and smtp and try again.

I see what your saying about drupal_mail_wrapper. It looks like mimemail only puts its version in if:

if (strpos(variable_get('smtp_library', ''), 'mimemail')
  && !function_exists('drupal_mail_wrapper')) {
   function drupal_mail_wrapper($mailkey, $to, $subject, $body, $from, $headers) {

The problem gets a little worse too. If you go in to mimemail and set to all outgoing messages, the smtp_library variable will get set to "mimemail". If you jump back over and re-configure smtp, the smtp_library variable will get set back to "smtp".

I'll mess around tonight and see what I can come up with.

Thanks,
-- Jason

axle_foley00’s picture

I tried the patch but unfortunately I'm getting the following error:

Hunk #1 FAILED at 157.
1 out of 1 hunk FAILED -- saving rejects to file smtp/smtp.module.rej

I'm not quite sure what I'm doing wrong with the patch. It's my first time actually applying patch. I have both an smtp_old and smtp directory with the necessary respective files and the smtp_mimemail.patch file at the same level. I then called 'patch < smtp_mimemail.patch' and it asked me which file I wanted to patch, so I chose 'smtp/smtp.module' and I get the error stated above.

Is this the correct procedure or am I missing something?

redben’s picture

subscribing

oadaeh’s picture

Jason, first off, thank you for your time and effort in getting this done. This is huge step for Drupal users in allowing them to use both modules simultaneously.

I've just tested the patch, and here's what I get so far:

1) When sending a test e-mail from the SMTP support configuration page (admin/settings/smtp), I get the following error:

Fatal error: Call to undefined function drupal_mail_wrapper() in /var/www/drupal5/includes/common.inc on line 1961

The settings save fine otherwise, but the test e-mail does not go out.

2) When sending an e-mail using the Contact module, I get the following warning message:

warning: Invalid argument supplied for foreach() in /var/www/drupal5/sites/all/modules/mimemail/mimemail.inc on line 315.

The e-mail sends and arrives just fine. BTW, line 315 is in a part of the Mime Mail code that shouldn't (AFAIK) be being executed, so I'm not sure why it's being triggered. Are you not seeing this? I installed the modules (Mime Mail 5.x-1.0 & SMTP 5.x-1.x-dev) afresh and re-applied the patch but still got the error.

3) When sending e-mails with the Mass Contact module, all tests passed (Yay! :^)), except when sending a plain text message with an attachment. The attachment is not received, though the e-mail is. This may be a Mass Contact issue, so I'll look into it further later on when I have more time.

I haven't yet tried any other modules. Those modules were already installed on my development system. :^)

Taking a slightly different track, there are some other notes I have about the patch itself. The patch includes changes in the code which are not a part of this problem. Please do not include other changes as it makes the code review take longer for me. I see that the changes streamline the code, but please make a separate patch for them, so they do not cause confusion and so that they can be reviewed independently of this issue. Along that same vein, please try to leave the spacing as it is in the module. The module may not follow Drupal's Coding standards, but fixing that in the same patch creates more noise that makes it difficult to sift through what is important and what is not. I will be fixing that later.

One more thing, although the patch applied cleanly (except for trailing CRs), please follow the guidelines set forth on the Drupal Patches page, when creating patches in the future.

Again, I thank you for your work here and taking care of this important issue.

jsm174’s picture

No problem. Thanks for the comments. I was waiting to get some more feedback before I took another stab at it.

1) I think this problem may be based on the order in which the modules are enabled. If you go into mimemail, the smtp_library variable gets set "mimemail". If you then go into SMTP, it will then get reset back to "smtp". This messes up the way I coded around adding drupal_mail_wrapper() function.

So I'm wondering if the mimemail is enabled and the the smtp_variable is set to mimemail, should we not set the smtp_library variable and then maybe do a drupal_set_message( "Mimemail is already enabled, ... " );

2) I was not seeing that. I will do some more testing.

3) I never tried the mass contact module, so I'll check that out as well. I tried out attachments in a variety of scenarios, but again, I probably missed something.

4) darn! I thought I did follow everything. :) I did a diff -urp. I guess I should have done a dos2unix. I'll go back and remove the additional changes.

-- Jason

oadaeh’s picture

1) I think this problem may be based on the order in which the modules are enabled. If you go into mimemail, the smtp_library variable gets set "mimemail". If you then go into SMTP, it will then get reset back to "smtp". This messes up the way I coded around adding drupal_mail_wrapper() function.

I saw that you mentioned that in a previous post, but I didn't realize you were talking about the variable, so I didn't see it. I now see what you mean.

So I'm wondering if the mimemail is enabled and the the smtp_variable is set to mimemail, should we not set the smtp_library variable and then maybe do a drupal_set_message( "Mimemail is already enabled, ... " );

It looks like line 52 is the culprit:

  if (variable_get('smtp_on', 0)) {
    $smtp_path = drupal_get_filename('module', 'smtp');
    if ($smtp_path){
      variable_set('smtp_library', $smtp_path);    //    **  <-- This line here  **
      drupal_set_message(t('SMTP.module is active.'));
    }
...

You'll probably need to add a check there to find out if Mime Mail is installed and enabled and not reset the variable if it is. I don't think you need to post a message about.

3) I never tried the mass contact module, so I'll check that out as well. I tried out attachments in a variety of scenarios, but again, I probably missed something.

We should probably test it with a variety of mail out modules to make sure we're reasonably sure it works as advertised.

JaceRider’s picture

Thanks for the patch. It is working pretty well.

liquidcms’s picture

I have written a couple modules that hook in to the drupal_mail() function using the mail_alter hook - but these don't work with mimemail as, sadly, they do not have a mail_alter hook. I am looking at the only way to do this to be write their engine and prepare functions. I have started doing this but realized i will also lose smtp support when i am using mimemail functions.

I think some of the work you are diong here may help me out significantly.. thanks.

sinedv’s picture

Hello Jason,

first of all thanks for your contribution to solve this big smtp issue !

I try to use your smtp patch to use mimemail trough smtp.
- seems to be ok to apply the patch

--------------------------
|diff -urp smtp_old/smtp.module smtp/smtp.module
|--- smtp_old/smtp.module Wed Mar 19 16:13:49 2008
|+++ smtp/smtp.module Fri Apr 4 16:08:45 2008
--------------------------
Patching file smtp.module using Plan A...
Hunk #1 succeeded at 157.
done

- I still have the bloody message :

PHP Fatal error: Call to undefined function drupal_mail_wrapper() in /home/_services_/httpd/emea-cc.sophia.bsf.xxxxxx.fr/html/includes/common.inc on line 1961, referer: http://emea-cc.sophia.bsf..xxxxxx.fr/?q=admin/settings/smtp

- I understand there is still an issue with the order to setup mimemail and smtp ... but I'm completely loosed ...

- It seems that was working at a time ... but now I can't retreive the right setup :(

I really need help to be able to stabilize my intranet site and be able to send mail trouht smtp (this is the only way due to server configuration)

many thanks in advance for your help !

--Vincent

oadaeh’s picture

Status: Needs work » Fixed

Code submitted here: http://drupal.org/cvs?commit=121743

If there are problems, create a new issue.

I won't guarantee there are no bugs, but I did try to do quite a bit of testing to eliminate the possibility.

FYI, I ran though quite a number of tests with quite a number of modules and, where necessary, tweaked the code as required. The only real changes I needed to make were to add melon's fix in #12, and to tweak line 56 (actually, add 57) as discussed in #18, #19 & #20.

All in all, jsm174's patch was pretty good.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

a_c_m’s picture

Version: 5.x-1.x-dev » 6.x-1.0-beta3

Should this be working for D6 versions of both of these modules as well?

I just checked the D6 code for mention of "mimemail" and "smtp_mailengine" and nothing, so i guess the code hasnt made it in yet.

a_c_m’s picture

Status: Closed (fixed) » Active
oadaeh’s picture

Version: 6.x-1.0-beta3 » 6.x-1.x-dev

This is not working in Drupal 6. This module was ported before the Mime Mail module, and extensive changes were made to this module at the same time. Now that Mime Mail has a Drupal 6 compatible release, I can add that functionality back in, although it still might be a while before I get the time to do it.

If anyone else has the time and capability, submit a patch and I'll get it in sooner. :^)

a_c_m’s picture

We would be willing to sponsor the development of this feature in D6, please contact me via my form with an idea of how much it might cost and when you can do it. We ideally need it within the week.

gustav’s picture

Has work been started on porting this to D6?

challa.kamal’s picture

Hi

Could any one please send me the modified mimemail and smtp modules. because iam not femiliar with these patches ,

Please i deployed both the modules in my projects and now simplenews is not working, Please some one provide me the files

Thanks in Advance
Kamal Challa

mac_perlinski’s picture

I guess it's faster to google keywords drupal apply patch or just drupal patch than waiting for someone to do it for you? http://drupal.org/node/60108

Mac

Magnus’s picture

subscribe

eliosh’s picture

martinkrupicka’s picture

subscribe

yang_yi_cn’s picture

Status: Active » Needs review
FileSize
4.97 KB

Thanks for #11, I read it and rolled a patch for D6. It's working fine in my project, tested with sending a Simple Newsletter issue in HTML.

The idea behind the patch is that,
1. both mimemail and smtp are trying to set the smtp_library variable, which may cause problem.

so in the system_settings function, I make smtp module do nothing to the smtp_library variable, if the mimemail module exists.

2. both mimemail and smtp have the drupal_mail_wrapper() function.

mimemail module has its own drupal_mail_wrapper, and within its wrapper, it is capable of using different mail engines, for modules implementing it's hook. So, I choose not declare drupal_mail_wrapper() in SMTP, but implement hook_mailengine in SMTP module. for mimemail.

3. For some reason, when sending E-mail in text and html, mimemail set the content-type to multipart/alternative, but the code in SMTP module actualy cannot deal with it as a multipart/alternative. But when I change the type to 'multipart/mixed', the handler in SMTP module does the job.

I'm not very familiar with the RFCs, so don't know a better way of doing it, but at least it works.

danielkorte’s picture

@ #36

I just tried your patch and it worked great!!!! Thank you so much! It solved a ton of my problems.

Great work!

dkruglyak’s picture

Status: Needs review » Reviewed & tested by the community

Worked for me too. I think it is about time to commit.

StephenFresh’s picture

Comment - edited - it appears to work with my D6 with smtp mimemail ubercart rules views cck fckeditor.

fabio84’s picture

IMHO the problem is in the way mimemail was implemented.

I'm relatively new to Drupal and I don't know the history of these "old" modules and how they evolved with new versions of Drupal. But I can see that in Drupal 6.x emails should be processed using hook_mail_alter() and sent using drupal_mail().

drupal_mail() calls modules that implements hook_mail_alter, and sends the email using drupal_mail_send(). If a module has defined drupal_mail_wrapper(), drupal_mail_send() uses this function, otherwise it uses mail() from php library.

Mimemail implements drupal_mail_wrapper to "catch" messages sent using drupal_mail(), and it's a wrapper for the function mimemail(). mimemail() calls all functions that implements hook_mail_alter(), but these function are called twice if the mail comes from drupal_mail().

I think mimemail should implement hook_mail_alter() to generate the content of the email. I think it can do its work also using this hook. The function mimemail() may stay because it has more features than drupal_mail and some modules are using it, but it should use drupal_mail_send() instead of *_mailengine for a better compatibility between modules.
___

I was searching information about these modules because I have to implement a newsletter for a website, but unfortunately these two modules seems not able to work together with Simplenews. (btw Simplenews lacks some features, too). I like Drupal, but (sadly) for this time we have to stuck with phplist. I hope these modules could be ready for the next time.

srjosh’s picture

Subscribing

StephenFresh’s picture

I've just tested a patch for mimemail (http://drupal.org/node/501722) to handle rules emails as html better - which seems to work for people. The problem is I'm using the above patched smtp module (which worked prior to rules issue), I get this error when trying to trigger email sending via rules-mimemail-smtp:
"The submitted from address () is not valid."
this happens with a correct from address and also blank field -the error to me looks like when fckeditor adds code to email address fields rendering it not valid eg:
<p>emailaddress@test.com</p>

Any pointers or help to get these patches working together?

StephenFresh’s picture

Deleted - my bad

Mark_Watson27’s picture

I have applied the above patch and it gets the email sent out fine.
However the from address isn't being respected, I realise this is being address elsewhere but wanted to note how I got it at least showing the From address from the MailHeaders
In the smtp.module file in smtp_drupal_mail_wrapper I commented out the lines 347 and 356 where it checks the headers for from, so it's now:

      case 'from':
        //if ($from == NULL or $from == '') {
          // If a from value was already given, then set based on header.
          // Should be the most common situation since drupal_mail moves the
          // from to headers.
          $from           = $value;
          $mail->From     = $value;
          // then from can be out of sync with from_name !
          $mail->FromName = '';
          $mail->Sender   = $value;
        //}
        break;

so at least my mails now show the from address.

StephenFresh’s picture

Ignore this post

Sutharsan’s picture

@StephenFresh: don't hijack this issue! This issue is about collaboration of SMTP and Mime Mail module.
Search the mail-related issue queues (Simpelenews, Mime Mail, etc) for issues on inserting breaks. I'm sure this has been reported before.

StephenFresh’s picture

My apologies - just thought I'd mention issues I'd encountered when using this patch - had I thought it was unrelated I would never have posted it here.
Thanks for the reprimand.

johngriffin’s picture

This patch also worked for me, now I have an option for Mimemail to use SMTP as the mail backend instead of the default mail() function.

Looks like this is still not in an official release of SMTP yet though.

franz’s picture

Actually, the patch works fine, but creates another bug:

1) Patched SMTP
2) Configured Mimemail to use SMTP engine.
3) Try to send an e-mail without Mimemail (like notifying a new user)

It fails, unless you set Mimemail to be used for all mail.

franz’s picture

Status: Reviewed & tested by the community » Fixed

I debuged a little and found out that the patch made smtp not register the drupal_mail_wrapper function. But Mimemail is already smart enough to not register his own drupal_mail_wrapper function if smtp is enabled, so the mail system tried to find the wrapper without sucess (check lines 175-177 of includes/mail.inc)

So I just removed the check for module mimemail and let the drupal_mail_wrapper always be the smtp's. I tested with simplenews and non mimemail user notifications and it seems to be working fine.

http://drupal.org/cvs?commit=286922

Sorry, forgot to credit everyone in the message. =/

johngriffin’s picture

Status: Fixed » Reviewed & tested by the community
FileSize
1.13 KB

Franz, I think that commit will break the "Use mime mail for all messages" option in Mimemail. Please check out my patch (against HEAD), which I think should work in harmony with the current release of mimemail.

I only declare drupal_mail_wrapper if mimemail has not been set to be used for all mail.

I also changed the condition under which we set smtp_library as we only want to leave it alone if mimemail is being used for all mail.

I've tested this patch with Simplenews HEAD (sending HTML) and mimemail 6.x-1.x-dev. HTML and Plain text system mails work fine.

franz’s picture

Status: Reviewed & tested by the community » Fixed

It makes a lot of sense, thanks for the light, johngriffin

I hope this is the final solution.

Commited in -dev.

Status: Fixed » Closed (fixed)

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

TripleEmcoder’s picture

Has anyone noticed raw HTML visible in e-mails when using this?

luckysmack’s picture

I know this is an old thread, but im using these two modules together and they dont seem to be working properly. In mime mail i do tell it to send via smtp, which it does, but it does not send the email in html format which defeats the purpose of using mime mail. It only sends the email in text format. Im using these together with simple news module to set up a newsletter on my site. i have told simplenews to send via mime mail. Mime mail has the "send all messages from mime mail" option selected. But still does not send via email.

yang_yi_cn’s picture

for the "raw HTML" problem, it's probably because mimemail inserts attachments into the html can make it "multipart/related", which SMTP module seems not able to handle.

I don't have time for that right now so I'll just give up SMTP module and use mimemail only. My production server has local SMTP anyway.

liquidcms’s picture

so is bottom line that Drupal still has no solution to send smtp authenticated html email? pretty scary..

melon’s picture

@liquidcms: Have you evaluated the PHPMailer module yet?
For a long time I used SMTP module and I had no clue about the phpmailer module. It's playing nice with mimemail so I decided to replace smtp with phpmailer on nearly all my sites. You might want to give it a shot.

liquidcms’s picture

thanks melon.. checking it out now... i have used it before.. just not sure i have used it with mimemail.

thanks.

liquidcms’s picture

yes, phpmailer seems to allow me to use mimemail and smtp auth; just breaks mimemail from sending html emails.. :(

franz’s picture

melon and liquidcms,

I've used SMTP module and mimemail without problem on a number of sites. Are you sure you're configuring them correctly?

liquidcms’s picture

yup, all working now!!

Kristen Pol’s picture

Although this issue was closed, there was a scenario noted in #42 above that was never addressed.

I have opened that as a new issue and have a patch:

http://drupal.org/node/1171122

neha.jaha’s picture

Priority: Normal » Critical

Hello,

I am new to drupal please help me out....

i have configured both modules to my website

1.Smtp authentication
2.Mimemail (for attachments purpose)

but when i active Smtp authentication module i am not able to send attachments.

is there any other solution for same...

itserich’s picture

Thanks to people who commented on PHPMailer module. http://drupal.org/project/phpmailer

As a novice, all I want (currently) is emails which appear coherent, with paragraphs and clickable links. Mime Mail worked fine.

Then, I wanted to use SMTP to improve deliverability. I would not have tried PHPMailer except for this thread, because I was looking for a module with SMTP in the title.

In any case, PHPMailer seems to integreate seamlessly with Mime Mail, though I am a novice. I do not understnad why configuring email seems to be one of the hardest tasks for a site.

simonp-1’s picture

I'd just like to second the comment above.

It took a little while to figure out, but to use SimpleNews to send out HTML emails through SMTP I needed the following modules:
http://drupal.org/project/phpmailer
http://drupal.org/project/mimemail
http://drupal.org/project/smtp

Once I worked that out they were simple to install (as in the installation notes were correct and easy to follow) and configure.

franz’s picture

simonp, smtp and phpmailer do the same thing, so it doesn't make much sense to have both installed.