php class to handle and parse the courier mail server format - php

does anyone know if there's a class out there that parses courier mailboxes (ie: courier imap mail server)? returning lists, and parsing individual messages?
this is not a protocol issue, i'm not interested in connecting to a remote mail-server. rather, i'm interested in manipulating the local mail-server via filesystem.
In particular, the mails are kept in files, but those do not contain the "from" email address, i am completely puzzled by this and more issues. Does anybody have any experience with this?

Maybe the Zend_Mail component of Zend Framework might help, here ?
(If it's like several other components of ZF, it might be do-able to "extract" it from the framework, to use it as some standalone component)
Quoting a portion of this page : Reading Mail Messages :
Zend_Mail can read mail messages from
several local or remote mail storages.
And there is table of features :
Feature Mbox Maildir Pop3 IMAP
Storage type local local remote remote
Fetch message Yes Yes Yes Yes
Fetch MIME-part emulated emulated emulated emulated
Folders Yes Yes No Yes
Create message/folder No todo No todo
Flags No Yes No Yes
Quota No Yes No No
So it seems Zend_Mail is able to do at least some manipulations on "local" mail -- including reading them (Not sure whether Courrier uses Mbox or Maildir, but as both are supported...).

after some searching, this class: http://www.phpclasses.org/browse/package/3169.html#download does a pretty decent job at parsing the raw mail message, thank you guys for helping out.

Related

preview email development in PHP

Once or twice a year i find myself in the position of having to develop complex emails.
They often include Plaintext and Html versions, along with attachments and other headers.
Previewing the development using standard send/receive is painfully slow and tedious.
What i'm looking for is a local testing platform that processes the mail function and provides a mail client style preview with access to alternate views, headers, etc. Or possibly a real mail client that can take mail directly.
I've searched and searched but no luck so far, hopefully someone can point me in the right direction.
Thanks in advance. TT
I'm not sure if this is what you want but you can use your localhost mail and access it via thunderbird for example
How do I read local email in thunderbird? - Ask Ubuntu
Via this way you don't have to wait endless for mail to be delivered as it's local. And you can see your send mail in a actual mail client
I don't know any software but I had some good experience with the following online service: http://litmus.com/ It's somewhat like browserstack. (live crossbrowser testing tool)
I use Papercut, which listens to a SMTP port, catchs all e-mails and shows headers, source, text and html view. It's very useful!
I have now solved this.
In the php.ini file there is an option to set an export path for the mail function called sendmail_path.
I set this to tee mail.eml > /dev/null and it now saves the sent mail to the same directory as where the function is called and i simply open it with my mail client.
sendmail_path = tee mail.eml > /dev/null
2 notes on this.
this is a solution for unix platforms only.
the file extension has to be set to suit your chosen mail client
For a task like this I use fakemail for receiving the mails into a maildir and mutt for reading the mails. Mutt can also be configured for reading HTML mails.
If you just want to log the emails without reading them, you could use the "logmail" approach described in this article by Chris Shiflett:
Edit: The lastcraft.com host seems to be down at the moment, my Google search for "fakemail" revealed this Python project that might be helpful: https://github.com/isotoma/FakeEmail
If you're just looking to preview your HTML emails (and alternatively, if you need help designing them) you can sign up for a free MailChimp account. It's actually an email send service, but they also have an interface for a drag-and-drop email builder.
For your situation, you could use the "code your own" tool, drop in your HTML, CSS, plain text, etc. and then preview the email in all sorts of email clients, test at different screen resolutions, etc.
(*I am not affiliated with MailChimp)
You can also try https://github.com/ycecube/phpmaildebug.
It uses the php's sendmail output to capture the mails.

Mail forwarding in PHP

I am developing a dynamic mail forwarding component for a website.
The concept is that
- a user will send an email with arbitrary content to a special email address on the server
- based on the "to" and "subject" line content, the system will forward the email to a group of (external) email addresses that are pulled from a mysql database
I'm running on a shared webhost (Bluehost), so I don't think I have any advanced access to the mail infrastructure to do this for me (no .forward files, for example). The target email list is dynamic, so I can't use cPanel to set up static forwarding.
I have the incoming mail coming to a PHP script, but the processing looks challenging, especially for the MIME parts - multipart, attachments, etc. I have looked at the PEAR Mail / MIME stuff, but it seems overkill to completely decode and re-encode the msg...
Any tips?
I use phpMailer for sending email from PHP.
I implemented exactly the same concept in mod_perl a few years back. Be aware that much of your outgoing email will likely be blocked if you send a significant volume. And if your system can be hacked (and that sounds at least plausible), spammers may find it and use your system, which would then lead to all your outgoing email being blocked.
Sending email is more difficult than it should be (if considering only the tech) thanks to spam and spam filters. These days I often find it easier to write code which uses a third-party service to actually send the emails, feeding the addresses over an API. I've had good luck with MailChimp and Contactology APIs recently.
EDIT: as for the incoming email: If you weren't in a shared hosting situation, it wouldn't be that hard - simply capture it, strip the headers, and pipe it back out to a new address. I'd have to agree with Conrad I guess on that point -- a shared host PHP script seems like a rather sub-optimal environment to try and solve this problem. If you can't use system() to pipe it back out directly the the mail infrastructure, I think you do have to completely parse the incoming email and reassemble it.

PHP Mail client library

I know there is plenty of PHP mail libraries out there, but most of them are designed to send emails, is there any library that will help me fetch emails from imap/pop3 accounts, deal with attachments etc?
I'm already using imap_* functions from PHP IMAP extension but using it is problematic, as I have to re-invent the wheel in most cases (ie. parsing the result of imap_fetchstructure to get to attachments)
Mayby there is any ready to use lib build on top of imap_* or similar, that will help me deal with fetching mails, without re-writing all that logic behind well known problems?
I have missed the obvious Zend_Mail will do the trick
Here is a PHP Pop3 Client that I use for a script on my server.
http://www.phpclasses.org/package/2-PHP-Access-to-e-mail-mailboxes-using-the-POP3-protocol.html
You could easily use that to create a graphical layout, but I have not had the necessity for it.

is there something wrong with using php's native mail function?

i tried googling but sadly i get only documentations (or am i using bad keywords)
anyway
i can see that alot of programmers (even those im working with right now) does not seem to approve to using the php native mail function and resorts to using some other framework like sendmail? swift mailer etc...
i'd like to know why? are there really disadvantages to using the native mail function?
if so how does the mailing frameworkds solve that or how are they better??
There's nothing wrong with it for sending simple plain text emails.
However, once you get into multipart mime emails (say, you want an HTML version or to add an attachment) then you have to build the email yourself, and it can be quite tricky to get all the headers and encoding correct. In this case you're better off using a library.
The PHP manual for function mail mentions that there are some restrictions with the mail function and one of these are that the function opens and closes an SMTP socket for each email. The mail function works good when you just want to send a mail or two.
As far as I'm concerned, all of these problems pale in comparison to the major security problem:
Mail header injection: ( http://en.wikipedia.org/wiki/E-mail_injection , and php specific info: http://www.damonkohler.com/2008/12/email-injection.html )
Whereby a spammer bot spiders your site and, finding a vulnerability in your script that is easy to still have when using the very insecure mail() function, IS ABLE TO SEND EMAIL FROM YOUR SERVER TO AN ARBITRARY LIST OF CONTACTS, essentially turning your script & server into a cog in their spam email machine.
I recommend never using mail() with user input, and in general, just making use of PEAR::mail instead. http://pear.php.net/package/Mail/
Using PHP's mail() function requires a properly configured sendmail or equivalent on the host the program is running. However, the Windows implementation is a bit different. If you don't have your MTA configured properly, you won't be able to successfully send emails from your PHP scripts. Like another commenter said on this thread, PHP manual explicitly states that each call to the mail() function opens and closes a socket. This can cause unnecessary delay in script execution.
Additionally, your development and testing environment may not have a public static IP address. Your IP address might be blacklisted by DNSBL, Gmail, Yahoo! and other popular email service providers.
Your best bet in this situation is to use a properly configured external SMTP server. Chances are your employer has already provided an email account with SMTP access. If you don't have one you can use a Gmail account. Gmail provides SMTP access to all email accounts.
You can write scripts to open a socket connection to the external SMTP server. When there are tried and tested open source libraries for this purpose, why write your own?
Incidentally, I wrote a blog post on the very same subject yesterday: Using SMTP With Zend Framework - Solve Email Delivery Problem
Best regards,

Has Anyone Here ever tried PEAR

Hi I have been reading alot of articles adoring the PEAR mail package and it seems like PEAR is something I need to try out.
I am interested in setting up a full mail server, similar to a conventional SMTP mail service; which incorporates mail queuing, resending with a backend database etc. My impression is that PEAR can do this but can its service be used with mail clients like outlook to send mail, just as how any any smtp server daemon can where one would enter a portnumber, server name and/or security protocol?
Thanks
No, PEAR isn't going to magically solve these problems for you.
PEAR is a collection of PHP classes that are meant to solve common problems faced by PHP users. The Mail packages offer code for interacting with different parts Email systems. They do not contain code for creating email systems from scratch.
For example, form the Mail_Queue documentation
The Mail_Queue class puts mails in a temporary container, waiting to be fed to the MTA (Mail >Transport Agent), and sends them later (e.g. a certain amount of mails every few minutes) by >crontab or in other way.
The MTA in this case in sendmail, postfix, etc.
Another example, from the Mail_Mbox documentation
It can split messages inside a Mbox, return the number of messages, return,
update or remove an specific message or add a message on the Mbox
Incorrect use of "an" aside, you are using this to read existing MBOX files, and not caring how they got there.
The Mail package is about interacting with existing mail systems, NOT creating replacements. You'll still need to understand how all those email systems work to create a "full mail server, similar to a conventional SMTP mail service". If you're doing this because you want to learn how email systems work, have at it. If you're doing this because you thing this will give your business some leg up in the email game, I laugh and say "good luck with that"
PEAR is a repository for lots of libraries. Some of them deal with mailing.
PEAR's Mail class is designed for sending mail only. It is not designed as an implementation of an SMTP server.
Pear Mail is an SMTP sender aka client, not an SMTP server. Although it's entirely possible to write server (any kind of server) in php that doesn't mean that writing an SMTP server yourself is necessarily a good idea as it requires quite some expertise to do it right (spam anyone?). If you want to see an SMTP server implemented in a scripting language, go have a look at Lamson, written in Python by Zed Shaw.
And while you're there, do read the About page. This quote says it all
However, as great as Lamson is for
processing email intelligently, it
isn’t the best solution for delivering
mail. There is 30+ years of SMTP lore
and myth stored in the code of mail
servers such as Postfix and Exim that
would take years to replicate and make
efficient. Being a practical project,
Lamson defers to much more capable
SMTP servers for the grunt work of
getting the mail to the final
recipient.
It seems to me that PEAR's MailQueue package may address your needs.

Categories