How command processing works - technical overview

A command consists of two main parts - a key and a value. In the command type: blog "type" is the key and "blog" is the value. There is explicit handling for commands related to taxonomy. Apart from taxonomy, there is general handling for properties on the node object. For example, commands are searched for and collected on an incoming message. If the command is specific to taxonomy, it will be processed according to the parameters explained in the "Taxonomy commands" section below. If the command is not related to taxonomy, the property on the $node object with the name "key" will get set with its corresponding value. For example $node->type = 'blog' would get executed if the command type: blog is found. Therefore, if you're using another module which owns a property on the node object, you can see how you could assign a value to that property by specifying the name of the property and a value in your mailhandler commands.

List of known mailhandler commands

Node settings commands

comment: 2
(0 if no comments, 1 if read-only comments)

format: 1
(To set the input format for your post. Should be numeric. If you've created custom input formats, they are at admin/settings/filters. In the default configuration, 'Filtered HTML' is 1, 'PHP code' is 2, and 'Full HTML' is 3.)

pass: password
(If you required a password on the configuration page, replace password with the correct password.)

promote: 1
(0 if you don't want it promoted)

status: 1
(0 if you don't want it published)

type: blog
(Provide the node type here. Examples: story, forum, or page. Use type=comment to force a comment. can be used with nid= command)

sticky: 1
Set whether the node is sticky

language: nl

Taxonomy commands

taxonomy: [term1, term2]

Use this to add the terms term1 and term2 to the node. Both of the terms should already exist. In case they do not exist already, they will be quietly ommitted. Brackets are required.

taxonomy[v]: [term1, term2]

Similar to the above: adds the terms term1 and term2 to the node, but uses the vocabulary with the vocabulary id v. For example taxonomy[3] will choose only terms from the vocabulary which id is 3. In case some of the terms do not exist already, the behavior will depend on whether the vocabulary is a free tagging vocabulary or not. If it is a free tagging vocabulary, the term will be added, otherwise, it will be quietly ommitted. Brackets are required.

Node and comment defaults

When defaults for settings like whether a node should be published or promoted to the front page are not defined in commands, the defaults on /admin/content/node-type/%node-type (where %node-type is the real name of a node type on your site) defined for that node type will be used. If you are posting a comment via mailhandler and you do not specify default published status in your commands, the permission system will be used. For example, if a user with only the 'authenticated user' role posts a comment via mailhandler and the 'authenticated user' role has the permission 'post comments without approval" then the comment will get posted in a published state. If the user does not have the permission "post comments without approval" then the comment will get posted in an unpublished state.

Examples

Posting to forum
A sample of commands that can be used to post incoming emails to a forum would be (including the square brackets):

type: forum
taxonomy: [My Forum]
promote: 0
status: 1

Where [My Forum] is the "term" in the "forums" vocabulary that was automatically created when a forum named "My Forum" was created (see Admin->Categories).

These can be put either on the configuration page for the mailbox, if you want them to be defaults, or at the beginning of the email.

Post a comment to an existing node

type: comment
nid: 54

A new comment will be created on node 54.

Comments

pasupathymahalingam’s picture

Hi,

I finally found out how to create and edit nodes and comments. Here is how

To create new node
1. In the 'To' field of the mail
2. In the subject of the mail mention the title of the node getting created
3. Write mail handler commands in the first few lines of the body
4. In the body of the mail write the text of the node

For example if you write in the subject 'test' and in the body of the mail write,

type: page

This is a test node

This will create a node of type page with title 'test' and Body/Text as 'This is a test node'

Note: type: command is required if you have not put it in the default command in the configuration. More over, if type: command is present in the default command in the configuration that takes precedence

To edit node
1. In the 'To' field of the mail
2. In the subject of the mail mention the modified title of the node
3. Write mail handler commands in the first few lines of the body
4. In the body of the mail write the text of the node

For example if you write in the subject 'test - changed' and in the body of the mail write,

nid: 10
type: page

This is a test node which is changed

This will modify the node whose node id is 10 and is of type page with title 'test - changed' and Body/Text as 'This is a test node which is changed'

Note: nid: command is required to identify the node which is getting edited

To add a comment to the node
1. In the 'To' field of the mail
2. In the subject of the mail mention the title of the comment
3. Write mail handler commands in the first few lines of the body
4. In the body of the mail write the comment

For example if you write in the subject 'test comment' and in the body of the mail write,

nid: 10
type: comment

This is a test comment for the test node

This will add a comment to the node whose node id is 10 with title 'test comment' and comment text as 'This is a test comment for the test node'

Note: nid: command is required to identify the node for which the comment is getting added. type: command signifies that a comment is getting added

To edit a comment to the node
1. In the 'To' field of the mail
2. In the subject of the mail mention the modified title of the comment
3. Write mail handler commands in the first few lines of the body
4. In the body of the mail write the comment

For example if you write in the subject 'test comment - changed' and in the body of the mail write,

nid: 10
cid: 5
type: comment

This is a test comment for the test node (This is changed)

This will edit the comment whose id is 5 that is attached to the node whose node id is 10 with comment title 'test comment - changed' and comment text as 'This is a test comment for the test node (This is changed)'

Note: nid: command is required to identify the node for which the comment is getting added. type: command signifies that a comment is getting added. cid: command signifies the comment id that is getting modified

Phoo.... It took me some time to figure out. BTW... I have still not figured out how to reply to a comment!!! Any body who has experimented on this, please reply

Note: default commands (in your mailbox configuration) if any are also taken into account while the mails are processed. If you leave them empty, make sure you add those commands in the first few lines of the mail. More over the commands you specify in the first line gets appended to the default commands. Hence if the default command says type:page and in your mail you say type:story, a page is created and not story!

echoeng’s picture

Has anyone figured out how to post to a forum? How did you figure out all of the options? Is there a file or something? Thanks for posting that!

number3’s picture

Yup, use the following below in your default commands or in in the first few lines of the e-mail you want to use to generate your content.

type: forum
taxonomy: [insert name of your forum topic]

You can also use the following below to do any specific actions you wish to do.

publish: 1
promote: 1
format: 3
comment: 2

Now, I haven't been able to figure out all the options. I've tried to look for thorough documentation on these options but I haven't found "jack".

And I'm still trying to figure out how to reply to a comment.

rsbecker’s picture

I have set up a system to submit forum posts to a moderated list, so status: 0 is set and a moderator must publish the post. Is it possible to set the 3 subscription flags as well, Posts Tagged With, This Post, and Posts of Type. All initially are set to 0.

Second question, is there a flag that would allow the moderator to delete the post if the decision is not to publish it? What flag would do that?

I assume the following are needed to do the edit, but what must be added to accomplish the above?
nid: 123
type: forum
status: 0
comment: 0

number3’s picture

To reply to a comment

You'll need the following
nid: 29
pid: 9
type: comment

nid is the node id (found in the node table)
pid is the parent comment id that you'd like to reply to (found in the comment table).

tjharman’s picture

This worked perfectly except my comment body was blank.

Very strange, any idea?

vkersten’s picture

Thanks for your help here!
I got it to work, finally.
What drove me nuts was this error message in the log:

Message Node submission failure: user@example may not create forum<br /> items.

Turns out i wrote type: forum in the rich text editor, thus adding a <br /> unwillingly :)
Switching to text-only made it all clear.

Also "/novalidate-cert" in extra commands for the mailhandler proved necessary to escape my hosters' self signed cert. (would even be nicer to store it somewhere, but that I keep for the next installment).

Thanks for this great piece of software!

newdoc2013’s picture

Hi all,

I have a website where I'd like to have submission to twitter. When a user submits content via the web all is dandy - the node is posted to twitter as configured with the twitter/oauth modules. However, when its submitted via mailhandler, the content is not posted to twitter. I have included the following command in mailhander:

twitter: 1

Upon retrieving mail from the mailbox, I get a message saying that the mail was retrieved and that the content has been posted to twitter, but nothing appears on twitter.

This seems to be the correct property on my node object?

Tips?

dman’s picture

It seems that incoming posts are identified as being owned by the user whose email submitted it. This is all totally clever and intuative, but stumped me for a while when trying to test.

To post to your own site - as you - your email address must be the one registered at the site.

If your site is blocked to anonymous submissions, incoming emails from not-your-email get retrieved ... but go nowhere. An error appears in the watchdog saying something like -
" Mailhandler: The e-mail address 'myemail@gmail.com' may not create mail items."
or (under Organic Groups)
" Mailhandler: Your submission is invalid: title: You must join a group before posting on this web site. "

I didn't have bounce messages on.

I tried making a dummy semi-authenticated account called 'mailer' that was allowed to post, and setting

user: mailer

in the default commands. Didn't seem to help. ... nor

name: mailer

Looking at the code I see that mailhandler_authenticate() just doesn't let this happen. :(

I was about to hack into it to allow $node->name be set ... when I realized what a hole that would be. I'm wanting to set it in the admin (safe) zone, but it gets read from the admin+submitted commands. Meaning it would be pretty easy to spoof. :(

I'm still working on this problem. In the meantime I just added my test-submit account as a user. Maybe I'll have to forward-bounce it or something.
I had to then ensure this user was in the right role to create content etc. Pretty straightforward.

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/

rsbecker’s picture

You should try installing the mailalias module. That lets a registered user list alternate email addresses in a field. So if you have a different email address at work or on your laptop Drupal recognizes it as you.

mdowsett’s picture

how about adding content via email into CCk fields in a node...is that possible?

MashsaM’s picture

Hi there!

I have drupal 6 and mailhandler is working fine with listhandler to create forum that mirrors a mailing list.

I found the comment command useless. I put it in the default commands and all it does is: all replies coming in by email have the same text in it - "2". That's because I wrote in the default commands "comment: 2". So if I wrote in the default commands "comment: no comments" I would get all comments emailed in with the text "no comments". Confused? me too...

Anyway I'm happy with the forum default settings.

nategasser’s picture

Even though all the examples show commands in this format:

promote: 1

I blanked and I omitted the space, like so:

promote:1

Yeah. That won't work.

Don't forget the space. :)

spjsche’s picture

I have added the following command in the default settings

type: daily_news_report
og_groups: [2]
promote: 1
status: 1

to mark the post to a specfic group, but it does not work - or have I done it wrong.

Any help would be appreciated.

Thanks

Panaromic.webdesign.com’s picture

This will not work according to the code. But it is a good idea extend to og group postings. The type can be either node or comment. But the code seems simple enough to understand and customize.

There is a function mailhandler_node_submit. This function you may want to customize to post to a specific og group.

Hope it helps.

spjsche’s picture

Thanks for the pointer, I will endeavour to review the function and see
if I can customize it for my needs.

Thanks
Stephen

GregoryHeller’s picture

@spjsche have you found anything out about this? I have a similar requirement: sending email to create a new node within a specific group. I was thinking another way to go might be creating different mailhandler email addresses for each group, though not sure how well that scales. It would still need something that does not exist, like a "og_mailhandler" module that lets you assign a particular mailhandler for each og

spjsche’s picture

Check this out => http://drupal.org/project/mail2og

Thanks
Stephen

MatthijsG’s picture

Owww yeah .... just what i needed!

======
There are 10 people who can count binary
They who can and they who don't

kentr’s picture

mailhandler_node_submit() is in mailhandler.retrieve.inc.

In case anyone's looking for it...

keeline’s picture

I have a Drupal 6 installation on a Linux server with postfix (smtp) and dovecot (imap) installed and working properly. I would like to integrate forums with email so that a message sent into the list address is added to the forum and subscribers to the forum receive emails to which they can reply and continue the forum thread.

The primary modules I am using for this task are forums, subscriptions, mailhandler, and listhandler. Here is what works:

* I can send an email (from an account with an existing Drupal user account) to the mailing list address defined in mailhandler and the message is received by smtp and handed over to the imap mailbox. At the cron interval the mailbox is checked by mailhandler and processed and posted to the forum (as a new message each time).

* Users who subscribe to the forum are sent a copy of the posted email by mailhandler + subscriptions.

Here is what does not work:

* The email message is From: the original sender. That is OK. However, when I hit "reply" in Outlook, it tries to reply to the original sender instead of the mailing list address.

It seems as if it should be possible to set the Reply-to: address for the email to be the list address if desired. However, I cannot find a suitable input for this in the admin form nor in the code for the two modules (mailhandler and listhandler).

I think what I am trying to do is possible and should be something others would also care to do. It would help facilitate forum usage by people in front of their computers and using mobile phones with an email option (e.g. iPhone).

I have tried various values in the mailhandler Default commands configuration but I have not come up with a working solution. Here is the most basic Default commands setting:

tid: 8
status: 1

I have tried setting the From header address to either the list address or "From: " followed by the list address. I have also tried to use commands like "user: ", "name: ", "From: ", "from: ", and so on without success.

Where can I find a list online or on my site of all of the commands which can be used in this Default commands field?

Also, since each message sent to the list address starts a new forum post, we don't get any reply threading which would be nice. I guess that the commands can be placed in the body of the email for processing to attach it to the node with the right type but we would prefer if this was an automatic rather than a manual procedure. Is there any help for this?

I've been working through all I can find on drupal.org and other resources for quite some time and hope that a developer or user can help. I've used PHP for 10 years and Drupal for 2.5 years plus we have a couple other Drupal guys working with us but we have not been able to come up with an answer thus far.

James

kentr’s picture

@keeline: Check out this module for "reply to" functionality

http://drupal.org/project/mail2web

Odd that listhandler isn't working. It claims to do what you want, from what I can tell.

I have not used either of these. I also need this functionality and would like to hear of your results.

savageanne’s picture

James - I'm still struggling to solve this also. I am in the exact state you are in (everything works except reply to: and threading). I imagine you've all ready seen this: http://drupal.org/node/298883 which certainly makes it appear that the threading is supposed to work. If you do solve this, please post so that I can learn from your experience, and I'll do the same. - Anne

savageanne’s picture

Here's half the story solved (at least if you are on gmail). Gmail doesn't honor the "reply to:" if the "from:" is set up as "Send Mail As...". Your main gmail email is set as "Send Mail as" so if you are testing by receiving mail in your gmail account and then hitting reply, it doesn't go to the list. But this is a gmail problem, and only impacts when you are replying to yourself. See http://www.google.com/support/forum/p/gmail/thread?tid=74d00d5e2605242d&...

flycatcher’s picture

Using Drupal 6.x, I add the taxonomy[v]: [term1] on the first line of the email and it will not assign it to the existing taxonomy term. It works fine in the default commands but I want to be able to leave it out of the default commands and assign taxonomy through the email.