sclark has asked for the wisdom of the Perl Monks concerning the following question:

I have written a web app that can search Active Directory for a user's cell phone email address, and provide a web form that emails that phone a message. The app is hosted on a LAMP platform. All mail on this linux box is sent through Postfix to our Exchange 2003 mail server for local delivery. I need to save this email in the 'Sent Items' of the web user's Exchange 2003 mailbox.

My ideal solution would be to send the email directly through Exchange so that the messae is delivered to the final destination and saved in appropriate Exchange folder.

If I have to code two parts (SMTP and save to Exchange) that is fine, too.

I'm running apache on linux and have both PHP/Perl available. The Exchange Server is Exchange 2003 and is running on the same LAN with the web server. I do not currently have IMAP enabled on the Exchange server.

What do you think my best options are?

Thanks in advance for you wisdom,

Sean Clark
  • Comment on Saving sent email from LAMP to MS Exchange Folder

Replies are listed 'Best First'.
Re: Saving sent email from LAMP to MS Exchange Folder
by radiantmatrix (Parson) on Aug 16, 2005 at 17:52 UTC

    The easiest way to do this is to work with your Exchange admins to set up a server-side delivery filter that triggers on a special header and source. For example, a filter that says For all mail origniating from <your SMTP server> and containing the header 'X-AddToSent: yes', move to <recipient's Sent Mail folder>

    Ideally, you'd implement some kind of strong authentication as well, so that no malicious individual can add to Sent folders by spoofing IP addresses. For example, you might cause your app to cryptographically sign the message and have Exchange use that as the criteria for determining the origin of messages.

    Then, all you'd have to do is either (a)add an Fcc: or Bcc: header to the outgoing mail containing the sender's address, or (b)send another copy of the mail to the sender.

    Of course, you could always just Bcc: the sender a copy of the message and provide instructions for users to set up filters instead...

    <-radiant.matrix->
    Larry Wall is Yoda: there is no try{} (ok, except in Perl6; way to ruin a joke, Larry! ;P)
    The Code that can be seen is not the true Code
    "In any sufficiently large group of people, most are idiots" - Kaa's Law
Re: Saving sent email from LAMP to MS Exchange Folder
by gellyfish (Monsignor) on Aug 16, 2005 at 18:00 UTC

    To save the message on the Exchange server you can use IMAP - you can use the append method with Mail::IMAPClient for instance to do this.

    /J\

Re: Saving sent email from LAMP to MS Exchange Folder
by ChrisR (Hermit) on Aug 16, 2005 at 20:00 UTC
    Now, I know this is ugly but it works for me on an Exchange 5.5 server. This comes from a web interface to our excehange server that I wrote a few years back.
    $imapp = Mail::IMAPClient->new( Server => 'servername, User => 'userid', Password => 'password', Uid => 1, Debug => 0 ); $tempuid = $imapp->append_string("Sent Items", $messagestring ,"\\ +Seen"); $tempuidarray->[0] = $tempuid; $imapp->set_flag("\Seen",$tempuidarray); if(!$tempuid){warn "ERROR saving to sent items: $@\n"; }
    I'm sure that Exchange 2003 is quite different from 5.5 but I would hope that IMAP is still IMAP. I don't know what LAMP is so I apologize if my reply seems ludicrous.
      I don't know what LAMP is

      Linux, Apache, Msql, P(erl|HP).

      --MidLifeXis

        Thanks. And thanks to radiantmatrix for the link http://onlamp.com/.

        It seems that while I did not know the acronym, I have been in the LAMP world for years.

Re: Saving sent email from LAMP to MS Exchange Folder
by bunnyman (Hermit) on Aug 16, 2005 at 18:01 UTC

    First, the quick and cheesy way. Send a receipt to the sender's email, and then have them use a mail filter on their side to simply move it from the Inbox to Sent Items. Simple and effective, but the user would have to have the filter set up.

    To really do this, I believe you would need to use a Windows box with Outlook installed. Then use MAPI to send mail from a program on the Windows side. Perl MAPI code example. You will need the user's password for this to work. You could have a service running on Windows that listens for a connection from the LAMP side, and then sends the mail this way.

Re: Saving sent email from LAMP to MS Exchange Folder
by sclark (Novice) on Aug 17, 2005 at 13:42 UTC
    Wise Monks,
    Thank you for your solutions. We'll problably try the exchange filter router first then wade into IMAP if need be. Thanks again,
    Sean