Best way to send new message notification to external email address
I would like to learn what the best approach to acomplishing the following task would be. I have spent a day or two reading through the forums here and searching the documentation and have found many clues as to how i might accomplish some of what i want, but nothing that seems to be an exact fit.
Thanks in advance for any advice given! If I am able to come up with a working solution i will be happy to post it here.
--What i am trying to accomplish --
I am configuring a message center instance that will be used as an "internal" email system for my customers to communicate with customer support (similar to the message center features found on many banking and credit card sites). In a nutshell, the system is locked down to prevent users from sending/recieivng email to the outside world. As far as that goes, we have been able to set things up the way we want. Users have an email address that can only recieve email from within my domain, and as part of the user registration process I am capturing their external email address (ie. joe_user@gmail.com) as an LDAP attribute.
I would like to add a feature that will send the user a notification message to their external email address whenever a new message arrives in the message center inbox. This message should only contain the subject line of the message center message (along with some custom text explaining that they have a new message waiting for them, etc).
I've come up with several possible approaches, which i will outline briefly:
1) take advantage of the (undocumented?) message_save_copy mapping table to save a copy of every message to the filesystem. I would then write a small script to periodically scan for new files (messages), parse out the userid and subject line, look up the external address associated with that userid, send the notification to their external email address, and then delete the file(message) from the file system. A possible concern i have with this message is that the files that are waiting for processing may contain sensitive personal information, and that by having them (even briefly) hanging out on the disk I am opening up a new avenue for compromise of that information. file system restrictions can address most of the concern here, but it would be nice to omit the body of the message and this does not seem to be an option with the message_save_copy mapping.
2) Create an MTA-wide sieve filter that could extract the information and pass it to an external process that would perform the appropriate lookup and notification. From my reading, it seems like a conversion filter might be the way to go, since that seems to be the only way to send the information i need to an external process, but I am not clear as to wether or not I can get the userid and subject line from the envelope of the message.
3) write a app (either in C or java) that watches the ENS queues for events and performs the notifcation actions when new messages arrive in the users mailbox. This method seems like the most work.
4) a variation of #1, create a filter or re-write rule that makes a copy of the message headers only and send that to a specific account, and then use the message_save_copy mapping to just save the messages for that account to the filesystem. I have also seen talk of a monitor/capture feature that may be used to do something similar but have not been able to find any documentation on it.
5) make use of a pipe channel to pass the needed info to an extenral process. However, I am not sure if there is a way to also make sure that the original message is still delivered the the users message center mailbox if i use this channel.
I would really appreciate any advice you can share with me on how to best handle this problem. So far i have found these forums to be an excelent source of knowledge about this messaging product.
thanks
-mike
# 1
Hi Mike,
> 5) make use of a pipe channel to pass the needed info to an extenral process.
> However, I am not sure if there is a way to also make sure that the original
> message is still delivered the the users message center mailbox if i use this
> channel.
This seems like your best starting approach and the easiest to roll out as you can do it on a user-by-user basis thus reducing the risk of a large change. You can add the attribute maildeliveryoption: program to a users entry (this will not affect the standard mailbox delivery). The program/script you pipe the message to is determined by the mailprogramdeliveryinfo: attribute (which also has to be added to the users entry).
A full explanation on how to register a program/script is listed in the Messaging Admin Guide ("To Deliver Messages to Programs Using the Pipe Channel").
The script can then parse the email, get out the subject line, look up the appropriate ldap attribute, create an email and send it off. This could be all doable in a several-line perl program.
Regards,
Shane.
# 2
The other option is to wait for 6.3, where the new sms/sieve thing is implemented. Likely that would do much of what you're looking for.
# 3
Shane -
Thanks for the advice, i am currently working to test that approach out.The only thing I am not entirely clear about is wether or not the original message will be delivered to the users inbox. From my reading of the admin guide, any result code from my external program other than 0 (EX_OK) is going to result in the message being bounced back to the sender or have its delivery defered. What does deferal of delivery mean exactly? Will it cause the message to be run back through the external program at some point when delivery is retried?
An exit code of 0 (EX_OK) reads to me like the message will be assumed to have been delivered by my external program and removed from the queue. I read elsewhere on the forums about a "delivery" program, would I need to pass the message off to this if I want the original to be delivered to the users message center inbox? Will I run the risk of creating an endless loop if i do this, or does "deliver" place the message directly in the users store?
Thanks alot!!
-mike cirioli
# 4
i have created the external script that the email will be piped to, run the imsimta program command, restarted the MTA and verified the program was registered:
/apps/msg_inst_dir/SUNWmsgsr/sbin/imsimta program -a -m notify_script -p notify.pl -g " %s" -e user/postmaster
/apps/msg_inst_dir/SUNWmsgsr/sbin/imsimta restart
/apps/msg_inst_dir/SUNWmsgsr/sbin/imsimta program -l
OUTPUT:
==================================================
Method_name: notify_script
Program_name: /apps/msg_inst_dir/SUNWmsgsr/data/site-programs/notify.pl
Argument_list: %s
Execute Permission : Postmaster
==================================================
I have also addred these attributes to one of my test users:
maildeliveryoption: notify_script
mailprogramdeliveryinfo: notify.pl
However, when I send email to this user, it shows up in their inbox with no indication that it is being run through the pipe program at all. Where should i begin looking to determine why its (apparently) not being delivered through the pipe channel?
thanks again!
-mike
# 5
Hi,
> Thanks for the advice, i am currently working to test
> that approach out.The only thing I am not entirely
> clear about is wether or not the original message
> will be delivered to the users inbox.
Yes. Each maildeliveryoption: <value> is treated as a separate delivery. For example enabling forwarding (maildeliveryoption: forward) and having local delivery (maildeliveryoption: mailbox) will be treated as two separate operations, so even if the forward failed for some reason local delivery will not be affected. This equally applies to maildeliveryoption: program.
> From my reading
> of the admin guide, any result code from my external
> program other than 0 (EX_OK) is going to result in
> the message being bounced back to the sender or have
> its delivery defered. What does deferal of delivery
> mean exactly?
The message will be requeued into the pipe channel queue for a latter attempt.
> Will it cause the message to be run
> back through the external program at some point when
> delivery is retried?
Yes.
> An exit code of 0 (EX_OK) reads to me like the
> message will be assumed to have been delivered by my
> external program and removed from the queue. I read
> elsewhere on the forums about a "delivery" program,
> would I need to pass the message off to this if I
> want the original to be delivered to the users
> message center inbox?
No you don't. A copy of the email will have been sent to the ims-ms channel for delivery.
Regards,
Shane.
# 6
Hi,
> I have also addred these attributes to one of my test
> users:
> maildeliveryoption: notify_script
> mailprogramdeliveryinfo: notify.pl
>
> However, when I send email to this user, it shows up
> in their inbox with no indication that it is being
> run through the pipe program at all. Where should i
> begin looking to determine why its (apparently) not
> being delivered through the pipe channel?
Three things to check:
1. The output of ./imsimta test -rewrite <users email address>
See whether deliver to a program is listed as a destination for the user (cut/paste output of the command).
2. The mail.log_current file. When you send an email to the users email address, what are the log entries?
3. The email queues. It could be the email was delivered to the pipe channel, but is stuck in the queue for some reason (e.g. permission issues on the script). What is the output to the following?
./imsimta qm sum
Regards,
Shane.
# 7
thanks shane...
I don't see anything about delivery to a program in the imsimta rewrite output, and the imsimta qm sum output shows there is nothing waiting in the queues. I don't have access to the log files at the moment (you have to love corporate lan security 8-) but that will be fixed by tomorrow morning. For the moment though, I am betting that the missing "program" delivery is where the problem is at. Attached is the output from the imsimta rewrite command:
bash-3.00# ./imsimta test -rewrite testlee05@test.com
forward channel= l
channel description=
channel user filter=
dest channel filter=
source channel filter =
channel flags #0= BIDIRECTIONAL MULTIPLE IMMNONURGENT NOSERVICEALL
channel flags #1= NOSMTP DEFAULT
channel flags #2= COPYSENDPOST COPYWARNPOST POSTHEADONLY HEADERINC NOEXPROUTE
channel flags #3= NOLOGGING NOGREY NORESTRICTED RETAINSECURITYMULTIPARTS
channel flags #4= EIGHTBIT NOHEADERTRIM NOHEADERREAD RULES
channel flags #5=
channel flags #6= LOCALUSER REPORTNOTARY
channel flags #7= NOSWITCHCHANNEL NOREMOTEHOST DATEFOUR DAYOFWEEK
channel flags #8= NODEFRAGMENT EXQUOTA REVERSE NOCONVERT_OCTET_STREAM
channel flags #9= NOTHURMAN INTERPRETENCODING USEINTERMEDIATE RECEIVEDFROM VALIDATELOCALSYSTEM NOTURN
defaulthost= test.com test.com
linelength = 1023
channel env addr type = SOURCEROUTE
channel hdr addr type = SOURCEROUTE
channel official host = uslcsec05.test.com
channel queue 0 name= LOCAL_POOL
channel queue 1 name= LOCAL_POOL
channel queue 2 name= LOCAL_POOL
channel queue 3 name= LOCAL_POOL
channel after params=
channel user name=
urgentnotices = 1 2 4 7
normalnotices = 1 2 4 7
nonurgentnotices= 1 2 4 7
channel rightslist ids =
local behavior flags= %x7
expandchannel =
notificationchannel=
dispositionchannel=
saslswitchchannel=
tlsswitchchannel=
backward channel= l
header To: address= testlee05@test.com
header From: address= testlee05@test.com
envelope To: address= testlee05@test.com (route (uslcsec05.test.com,uslcsec05.test.com)) (host test.com)
envelope From: address = testlee05@test.com
name=
mbox= testlee05
Extracted address action list:
testlee05@test.com
Extracted 733 address action list:
testlee05@test.com
Address list expansion:
testlee05@ims-ms-daemon
1 expansion total.
Expanded address:
testlee05@test.com
Submitted address list:
ims-ms
testlee05@ims-ms-daemon (orig testlee05@test.com, inter testlee05@test.com, host ims-ms-daemon) *NOTIFY-FAILURES* *NOTIFY-DELAYS*
# 8
Hi,
Spotted the issue:
>> I have also addred these attributes to one of my test users:
>> maildeliveryoption: notify_script
>> mailprogramdeliveryinfo: notify.pl
This should be:
maildeliveryoption: program
mailprogramdeliveryinfo: notify_script
The imsimta steps you ran earlier to 'register' the notify.pl script provides the linking between the notify_script value and the program to call (notify.pl). There is no need to explicitly list the name of the program in the users entry.
Regards,
Shane.
# 9
ah ha! thanks shane, that makes perfect sense. I'll make the change first thing in the morning and report back the results. I really appreciate the advice you have given, thanks so much!
# 10
I am having trouble finding any logs that show activity when mail is sent ( I am also dealing with issues where I don't have full administrative access to the message center server/install ARGHHHH). Do I need to increase the level of logging activity in order to see this type of information or am i looking in the wrong place (currently MSG_SERVER_ROOT/logs).
thanks
-mike cirioli
# 11
Hi Mike,
If you haven't enabled logging then you won't see any mail.log_current file (which logs todays mail traffic, mail.log_yesterday is yesterdays, mail.log is everything after that). A full explanation of this is available in the 2005Q4 Messaging Server Admin Guide.
To enable logging, you need to add the 'logging' keyword to the default channel definition line in the imta.cnf file.
before (your file may be slightly different to mine):
defaults notices 1 2 4 7 copywarnpost copysendpost postheadonly noswitchchannel immnonurgent maxjobs 7 defaulthost domain1.com domain1.com
after:
defaults notices 1 2 4 7 copywarnpost copysendpost postheadonly noswitchchannel immnonurgent maxjobs 7 defaulthost domain1.com domain1.com logging
The run:
./imsimta cnbuild;./imsimta restart
You should then see a mail.log_current file in <msg_server_root>/log/ after an email has been sent through the system.
Regards,
Shane.
# 12
Thanks Shane, that totally enabled me to figure out what the problem was. Turns out the mailsrv user did not have his own home directory!
The last piece of the puzzle is figuring out how to enable the original message to be delivered to the users inbox. I have a snippet of perl I found elsewhere on the forums that makes use of the "deliver" utility to put mail in the users mailstore. It apparently has to massge the message format a little before hand, but theortically it works. I have been told in other posts in this topic that i should not need to do that, but I am currently not seeing mail being delivered after my pipe program is run.
any ideas?
thanks again for all the help!
-mike
# 13
Hi Mike,
> Thanks Shane, that totally enabled me to figure out
> what the problem was. Turns out the mailsrv user did
> not have his own home directory!
Excellent :)
> The last piece of the puzzle is figuring out how to
> enable the original message to be delivered to the
> users inbox.
As I noted earlier, you don't need to do this yourself. If the user in question has the following attributes, then a copy will be delivered to the account AND a copy will be sent to the pipe channel (your script):
maildeliveryoption: mailbox (for local delivery)
maildeliveryoption: program (for a copy to be sent to the program)
What do you get for your test-user when you run:
./imsimta test -rewrite <test user email address>
Regards,
Shane.