In issue http://drupal.org/node/106944 yuttadhammo has posted a draft of a mailing module based on contact.module that closely emulates mail.module functionality.

It makes sense to consider this as a new iteration of mail.module (the 5.0 version).

Issues to consider and tackle include:

  • Is there any mail.module functionality not covered? If so, what? Can/should this be added back in?
  • Upgrade path: are existing settings and data maintained?

yuttadhammo, can you shed any light on these questions?

Thanks, Nedjo

Comments

NoahY’s picture

Dear Nedjo,

Sorry, I'm away from my computer at the moment, so I didn't get around to checking d.o until you wrote me.

I haven't used the mail module - actually I'm quite new to drupal, started with 4.7 and moved to 5 RC1 as soon as I saw it... once I realized that drupal had no such module as this, I started looking and found that I would have to downgrade. Since it didn't seem so intricate a feature, I made my own module. The mass_contact modula I made (could be renamed) has the following effects, as far as I can remember:

1) adds an admin menu for creating groups of mass contact recipients, containing one or more existing drupal roles (wouldn't it be nice to have an ajax-based gmail type thing for chosing from the user list on the fly as well?).

2) adds a menu item for the mass contact form which allows users with permission to contact any one of the above groups (can't remember if this permission is different than the admin permission for creating the above groups - should be made different if not yet)

3) adds an opt-out box to the user profile (thus profile.module may be required for this module - otherwise, I think a harmless error shows on activating the profile module if the mass_contact.module has already been installed and enabled (as it creates the profile table))

Sending a mass email does the following:

1) sends the email with the sending in the To: field, the users in the selected group in the Bcc: field (unless they've opted out)

2) saves a mass contact email node (type created on install)

3) sets a message for the sender saying that the email was sent to the recipients and the node was sent (should create a link to the node?)

If anyone has time to compare this to the mail.module, please let us know the results.

As for your second question, I don't understand; could you elaborate?

I am certainly willing to contribute to this project, I understand that you (Nedjo) are only maintaining it for testing, but I think certain things might make me undesireable as a maintainer - e.g. my relative inexperience with both drupal and php. Also, these next few months I'm not near enough to a computer to respond every day. Nonetheless, I am sure I can do minor modifications, answer questions and fix bugs as they come up, if that is helpful or desired. I'll try to check back here at least every week until I return to my base.

nedjo’s picture

Thanks for your detailed response.

I think this is the way to go for mail module. I'll take a look at your approach and work on integrating it. By question 2, I meant, how can we ensure that existing users' data and settings in mail module are maintained when they upgrade to the new version? E.g., mail module already has an opt-in, so we should make sure the new version works the same, or at least imports existing settings.

tky’s picture

Hi, nedjo:
I am a user of mail.module and I love it. It makes easier to send email-node and other types node to my site's members.

But I found that the subject and sender's name in email which sent by mail.module would be changed to bad code, like 皜霂憭批飛撗摮貊弦?, on my utf-8 coding site. I add a issue long time ago, but there is no any reply.
http://drupal.org/node/103407

Recently, I found a way to fix it. I have changed some codes of mail.module, like this:

/**
 * Send mail
 */
function sn_mail_enc_subj($subject) {
$escd = preg_replace('/[^\x09\x20-\x3C\x3E-\x7E]/e',
'sprintf("=%02X", ord("$0"));', $subject);
$escd = str_replace(' ', '_', $escd);
return "=?utf-8?q?" . $escd . "?=";
}

function mail_send($mail) {
  require_once('activeMailLib.php');
  $email = new activeMailLib($mail->mail_format);
  $email->From(sn_mail_enc_subj($mail->from_name). ' <' . $mail->from_address . '>');
  $email->To($mail->to);
  $email->Subject(sn_mail_enc_subj($mail->title));
  $email->Message($mail->message, $mail->mail_character_set, $mail->mail_encode);
  $email->priority($mail->mail_priority);

I hope this can help you to notice this little bug, and fix it on next 5.0 version.

Since I used this module to do lots work on my site and I wanna to upgrade to 5.0 site, it will be great to see the 5.0 version mail.module release as soon as possible.

Good luck!

NoahY’s picture

@Nedjo

Okay, when I get a chance, I'll look at the mail.module code and redo the opt-out (for starters) according to the mail module (unless anyone else wants to jump in). What tables does the mail.module use/create?

@tky

Can you check and see if the problem exists in the mass_contact module? It's here (for now): http://pali.sirimangalo.org/files/mass_contact/

tky’s picture

Hi, yuttadhammo. I have tested your module and found out it support UTF-8 coding.

But I found another problems at same time. When I use the mass_contact form to email my members(only two for test), I got two letter from myself and the receveier's email is the same with sender's. That's pretty weird.

On the redirect page after submitted the form, I saw these error massages blow:

    * warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/beta2/includes/common.inc on line 1929.
    * warning: Invalid argument supplied for foreach() in /home/beta2/includes/common.inc on line 1962.

I don't know where goes wrong. Maybe this should be another issue of mass_contact.

I also found out that it will create a 'copy' node automatically after sending mail. What is this function for?

NoahY’s picture

@tky

Yes, the idea is that you never (or I never) want to send mass emails disclosing the recipient email addresses, as this opens a big door for spammers. I suppose it should be an option, but I just hard-coded it to send the mail as a bcc to everyone, and put the sender in the "To:" field. Since you are the sender, that's probably why you get an extra copy - though I thought I added a check routine to omit the sender from the recipient list...

As for the error you get, I don't think I get such an error, but I'll check.

The node is for record purposes, and was a part of the mail module, I believe... or some other module, anyway. :)

Sorry, no work on integrating this with the mail module yet. Next week I should be able to do that. Also, I will do the following:

1) give an option to send as bcc or direct (To:)
2) give an option to save a record as a node or not.

Right now, both of these are hard-coded, no option available.

@Nedjo,

If I start working on integrating this into the mail.module, do you think they'd give me a cvs account? That would make it easier.

NoahY’s picture

Hi,

I've added two options to the mass contact form, which allow one to choose whether to hide the recipients or not, and whether to save a node or not. I'd like to make the default values settable in the admin menu, but I'm afraid that is beyond my ability.

Now to look at the mail module's opt out system. Any other compatibility issues I should look for?

NoahY’s picture

Sorry, the new version of the mass_contact.module is in the same place as before:

http://pali.sirimangalo.org/files/mass_contact/mass_contact.module

peterthevicar’s picture

yuttadhammo thank you for producing this much-needed module.

It seems to work well for me and gives me a function I have really missed.

If you don't mind me suggesting something, it would be to make the wording of the top of the mail configurable. I'm thinking of the header text:

'sent out a group email from'

Also the Notify module is in a section in Modules called 'Mail', whereas mass_contact uses 'email' - it would be good if they appeared in the same section.

Finally I don't see any opt-out in the user profile - am I looking in the wrong place? I don't have a profile.module you mention in #1. If I need it can you tell me where to find it?

Thanks again for doing this work.

Peter
(Using mass_contact 5.x-0.4-dev)

peterthevicar’s picture

@#9 - I remember now I deleted the profile.module to avoid a memory overflow. Have reinstated it and found the Subscriptions tab in the My account / Edit tab - that's everything working fine now, thanks again.

ATB, Peter

NoahY’s picture

@Peter - Thanks for the feedback. You can change the mass_contact.info file yourself in the meantime from "email" to "mail", but I'll change it on the website too. I'll try to figure out how to make the text editable too.

NoahY’s picture

Okay, here's the mass_contact module become a new (unofficial) version of the mail module. There is no option for sending node content, only a single role-based contact form available to privileged users and administrators. Opt-out has gone back to the mail module's "opt-in" system, for compatibility, but admin can now send to all users regardless of opt-in/out (as in the old mail.module). Here's the temporary url:

http://pali.sirimangalo.org/files/mass_contact/mail_new/

This is highly experimental, but working fine on my 5.1 server

Please let me know if you find the first bug :)

lias’s picture

Just wanted to say thanks yuttadhammo for all your work, lots of progress!
Lsabug

arzajac’s picture

Hello and thank you!

I downloaded and installed the mail_new modules from your server.

I however, cannot get it to work. I have assigned two roles to which I want to send mail, but when I click on Create content -> Mail, I cannot assign any role to which to send the message. Any ideas?

peterthevicar’s picture

Hi,

Thanks for the updates, which look really good. There are a few minor points:
1) The Navigation menu item should be /mail but it's put in as /node/add/mail which just redirects to /
2) There is a typo in the opt-in message: priviledged should be privileged
3) TINY point! the other module options in the Site Building menu have capitals but 'mail form' has a small m.
4) The help entry begins with a 0 (?) and doesn't explain you have to go to /mail to send a mailing out.

Also when I tried to send a mailing as a privileged user rather than site admin I got this and no mail was sent:

* warning: Invalid argument supplied for foreach() in /var/www/html/drupal-5.1/sites/all/modules/mail-5-1/mail.module on line 458.
* warning: implode(): Bad arguments. in /var/www/html/drupal-5.1/sites/all/modules/mail-5-1/mail.module on line 462.

Any ideas? It's possible none of the users in the group had opted in, would that explain it?

HTH, Peter

arzajac’s picture

Okay, I think I found the nature of my problem. I was running my site on Drupal 4.5 with the mail module and mail was defined as a content type. When I upgraded to 5.1, the mail module was no longer there, but the mail content was still there. I presently don't have the mail module active, but can still create content of the mail type. It is pretty much like creating a page or a blog entry, except it doesn't get sent out.

I gather when I have the mail module active, I am supposed to be able to send mail to any of the groups that I have defined (that does work), but I get no option. I just get the same page as when the module is not active.

Do you think this is a problem due to the fact that I upgraded? Is there any way to fix this or work around it? If I go to delete the mail content type, I am told that this will permanently delete the 60 mail messages that are presently on my site (publised like blogs - they were sent out as mail as well as published at the time.) I don't really want to delete them.

peterthevicar’s picture

@arzajac

To send a mail you need to point your browser at yoursitename/mail and select which of your defined groups you want to send the message to. You'll need permission to send mail and also the selected users must opt in to mails if you're not the sys admin.

That page also gives you the option of saving the mail as a new node.

HTH, Peter

NoahY’s picture

Title: Refactor mail.module based on contact.module » Refactor mail.module based on contact.module (5.x ONLY)

Thanks to everyone for the comments.

@Peter - Thanks for the good job debugging this:

1) The Navigation menu item should be /mail but it's put in as /node/add/mail which just redirects to /

That's not so... here's the code for that menu item:

		$items[] = array('path' => 'mail',
			'title' => t('mail'), 
			'callback' => 'mail_site_page',
			'access' => user_access('access mail form'),
			'type' => MENU_SUGGESTED_ITEM,
		);

Maybe you can elaborate on this a little. What link are you seeing as /node/add/mail ? There should be such a link, but it is automatically added by drupal, and should lead to the correct page for adding a mail node (which does not send an email). Try going to /admin/build/menu and see if the problem is still there (it seems to me that sometimes drupal is slow to update its menu items).

2) There is a typo in the opt-in message: priviledged should be privileged

That is so. Fixed. Thanks :)

3) TINY point! the other module options in the Site Building menu have capitals but 'mail form' has a small m.

That is so. Fixed. Thanks :)

4) The help entry begins with a 0 (?) and doesn't explain you have to go to /mail to send a mailing out.

That is so. Fixed. Thanks :)

Also when I tried to send a mailing as a privileged user rather than site admin I got this and no mail was sent:

* warning: Invalid argument supplied for foreach() in /var/www/html/drupal-5.1/sites/all/modules/mail-5-1/mail.module on line 458.
* warning: implode(): Bad arguments. in /var/www/html/drupal-5.1/sites/all/modules/mail-5-1/mail.module on line 462.

Any ideas? It's possible none of the users in the group had opted in, would that explain it?

Yep, that explains it. Here's the fix (already in the new code):

	// check for empty
	if(count($recipientouta) == 0) {
		drupal_set_message(t('There are no users in this category.  Mail not sent.'));
		return('');		
	}

Just put that before the offending line:

foreach ($recipientouta as $rnamea=>$rmaila)

Or download the new script from the same place:

http://pali.sirimangalo.org/files/mass_contact/mail_new/

@arzajac - I've updated the title to make it clear this is only for 5.x Remember that in 5.x your modules should be in //sites/all/modules/ instead of //modules/ Here's how to (hopefully) get the module back:

1) Make a new directory called //sites/all/modules/mail
2) upload all the files from http://pali.sirimangalo.org/files/mass_contact/mail_new/ to this new directory.
3) go to yoursite.com/admin/build/modules and activate the module Mail under Other

Don't use node/add/mail to send mail, use yoursite.com/mail as Peter explained. I would like to disable the add node link by default, as it is pretty much useless. Maybe I can use hook_menu...

Best wishes,

Yuttadhammo

NoahY’s picture

Fixed the node/add/mail link to be disabled by default. Hope it works.

peterthevicar’s picture

@yuttadhammo You are a star! All the fixes work fine, many thanks. In the navigation menu I think I had been confused because there are two entries called 'Mail' - one to add and one to send. I renamed the latter to 'Send mail' so I don't get confused again!

It all works fine and I tested the case where there aren't any opted-in users and get the nice new message and no errors. The only thing I'm not sure about is why the new mail node shows up in the 'Recent changes' block, but not in /tracker. Don't really care but it's an interesting question!

Many thanks, Peter

PS - is this now a proper module with its own issue tracker?

NoahY’s picture

@Peter

Thanks for the feedback. The reason it doesn't show up in /tracker is because it is not published, I think. I don't have a block called recent changes, must be from another module?

No, if Nedjo ever replies here, hopefully this will become the 5.x version of this same mail module, with its own issue tracker. i sent the mail.module files to him a while ago, no response yet.

arzajac’s picture

Thanks. I think everything is working the way it should.

somebodysysop’s picture

Category: task » feature

Great module. Is there a way to be able to support HTML formatting for mail messages?

NoahY’s picture

Category: feature » task

Hmm... a little early for feature requests... I've changed this back to a task, since the task of porting this module to be the new mail.module still hasn't been addressed. But yes, it should be easy to make the changes to the code to allow HTML. If you wan't to be the guinea pig, I could give you the code...

In mail.module add this:

		$form['html'] = array('#type' => 'checkbox',
			'#title' => t('Send as HTML'),
			'#default_value' => variable_get('mail_HTML_d', 0),
		);

before this:

		$form['bcc'] = array('#type' => 'checkbox',
			'#title' => t('Send as Bcc (hide recipients)'),
			'#default_value' => variable_get('mail_bcc_d', 1),
		);

and add this:

if ($form_values['html' == 1) $headers['Content-type'] = 'text/html';

before this:

 	if ($bcc == 1) // hidden recipients
	{
		$headers['Bcc'] = $recipientout; 
		$to = $from;
	}

and that may allow you to add html tags to your mail. I'll test it out myself too.

NoahY’s picture

Oops, missed a "]" in there. Don't use that code. I've added the correct code to the mail.module on my site. Download it and try it out yourself; it works!

NoahY’s picture

Maybe someone else could bug Nedjo to have a look at this again? He's probably just busy... One thing I noticed is that the old mail module accepted attachments. This one doesn't, but then neither does the contact module afaik. Maybe we can put it to a vote:

Yea if you think this module should replace the old mail.module for 5.x

Nay if you think this module should not replace the old mail.module for 5.x (or not without modification).

NoahY’s picture

I've just added the ability to add attachments to the module. Warning, use at your own risk. Works for me right now, after fiddling, but who knows if it'll work across the board. Anyway, if you don't use attachments, it should work as before.

somebodysysop’s picture

Thanks for HTML modification! Didn't see post earlier because for some reason these don't appear in my "Recent posts". Will give it a try.

somebodysysop’s picture

HTML modification works fine. If I were to make any other feature request, it would be to integrate this with /node/add so that we could make use of online HTML editor when creating mail messages. However, the mod you did works just lovely for now.

Thanks!

NoahY’s picture

@Somebody - I'm using the HTMLArea module and it shows up in the mail page. I don't understand what you mean by "node/add"; afaik, drupal doesn't come with its own html editor (I may be wrong).

Best wishes,

Yuttadhammo

somebodysysop’s picture

I'm sorry. What I meant was that when I click on node/add, I can use the TinyMCE editor to edit html in body field. I'll look into the HTMLArea module. Perhaps that's what I need. Thanks!

gurukripa’s picture

hi...
when r we going to get the contact all members feature committed to 5.1 :)
hope we can also get a contact importers feature so that members can use it to import email ids and invite large numbers to increase the community size..this is a feature request..hope u can add this one too ..or as a separate module ;)

somebodysysop’s picture

I need the functionality of this module, and in addtion the ability to send to groups as well. That's lot to ask I know in terms of feature requests. So, do you mind if I take the work you've done here and create a totally separate module designed to send to both roles and groups? Please let me know. Thanks!

cozzi’s picture

This is a very much needed module. I don't understand what the holdup is with giving yuttadhammo a CVS account? Or for that matter, giving this a new and unique project name.

Regarding post #33, I am confused because I thought this module would allow you to contact all members. (Clearly we need some documentation.) I will gladly volunteer.

Regarding post #34 - I suggest you don't fork this module as what SomebodySysop suggested is also much needed. SomebodySysOp - why not assist yuttadhammo in implementing your needed functionality?

What will it take to get the powers to be to understand how very, very, very import a full featured version of this module is to the Drupal Community? Is there someone we can contact to put a bit of pressure on?

BenK’s picture

+1 for all of the great work on this thread

Subscribing...

nedjo’s picture

I like the draft module, but haven't had time for the indepth review and fixing that would be required before I could maintain it. Looking at it afresh, I find it a enough different from mail module that it seems a new module rather than a new iteration. The key issue is node creation, see more below.

Issues and questions for me at this point include:

1. Support for existing mail.module installs. Will existing settings be recognized?

2. Node creation. The creation of a node of type 'mail' when this is not really a node is problematic because there is no support for this node type. If node creation is to be supported, it should be done instead via a custom content type. In general the module would probably be better off without this problematic piece.

3. Repeat of code. If we're leveraging off of contact module, it would be better to try first to directly reuse the code, rather than repeating it. Specifically, use contact.module's contact form, then alter it to fit.

I would support this as a new module. An alternative would be to commit this as a branch of mail module and go from there. In any case the main author of the module needs CVS write access for this to be a success.

I'll look into how to support the request of yuttadhammo for a CVS account.

NoahY’s picture

Hi,

about the "adding emails" issue, I don't think that is appropriate for this module, as it would mean using the site to contact non-members. There are other modules for that already, I think.

@Nedjo:

1. Support for existing mail.module installs. Will existing settings be recognized?

It supports the old opt-in, afaik. As for other settings, I didn't check.

2. Node creation. The creation of a node of type 'mail' when this is not really a node is problematic because there is no support for this node type. If node creation is to be supported, it should be done instead via a custom content type. In general the module would probably be better off without this problematic piece.

The point is to create a record of the email sent. I don't see what is problematic, but then this may show why I am not the best to lead the way in this module (see below)

3. Repeat of code. If we're leveraging off of contact module, it would be better to try first to directly reuse the code, rather than repeating it. Specifically, use contact.module's contact form, then alter it to fit.

I think you're referring to a form_alter or some such thing? Again, I would have to study up on that.

I would support this as a new module. An alternative would be to commit this as a branch of mail module and go from there. In any case the main author of the module needs CVS write access for this to be a success.

Okay, thanks to your kind support, I have CVS write access now. The question is what to do with it. I wish there were someone else who were more knowledgeable and perhaps more inclined to such a thing; I was hoping to offer my code to the community and go back to my own work. If I had to, I could start a new module and upload it as originally intended, but I wouldn't be much for offering more than bugfixes at this point. Sorry, the problem is more to do with my being a monk than anything else. Let me know if I should go ahead and open a new module, and what I should call it.

NoahY’s picture

Status: Active » Closed (fixed)

If I may close this issue...

Thinking it over, it's probably best for me just to go ahead and submit what I've made as a new module. I've started the process at http://drupal.org/project/mass_contact . If anyone objects or wishes me to do otherwise, please let me know. Otherwise, please submit bugs to the above project and hopefully I'll have a first version up within a day or so. I'm not going to work on feature requests, but I'll try to facilitate updates as best I can, given my own situation.