[Tutor] send file/mail to imap
Eric Brunson
brunson at brunson.com
Fri Dec 28 17:21:45 CET 2007
Tim's pretty spot on in his ruminations below, I just wanted to add a
few comments. Read inline.
Tim Golden wrote:
> Tim Michelsen wrote:
>
>> I have a mbox file locally on my notebook.
>>
>> I would like to send this file to my IMAP account using python.
>>
>
> Ummm. There seem to be two possible sources of confusion here.
>
> Number one is that you don't normally "send" things via IMAP,
> you use the IMAP protocol to *read* messages from a server-based
> mail store of some sort.
>
> Number two is that it's not clear whether the "mbox file" is
> merely coincidentally a mbox file (ie it might as well be a
> text file or a Word doc) or is -- as seems most likely -- a
> real mailbox which you want to make available to normal email
> clients via your IMAP server.
>
> So... reading way too much between the lines, I deduce that you
> want to have the mails in your mbox file available to your
> mail clients via your IMAP server. Am I right?
>
In order to use IMAP, the key word would not be to "send" the messages,
as Tim points out, which IMAP does not do, but do "copy" the messages
from one IMAP repository to another. However, (reading between the
lines) in order to do that you would need both repositories (mbox and
your IMAP server) available via the IMAP protocol and I doubt you have
IMAP access to the local mbox file.
> If so, you don't want to use an IMAP client, you want some
> other kind of file transfer mechanism, such as FTP or an scp
> command to get the file into the appropriate place on your
> mail server where the IMAP server will see it. You might
> then have to subscribe to it from your clients; depends on
> your setup.
>
This would definitely be the correct approach if your IMAP server uses
an mbox store and you have the ability to directly manipulate those
stores outside of the IMAP interface, i.e. root privs on the mail
server. However, knowing that all but the most rudimentary IMAP servers
do *not* use mbox and that there's a good possibility (based on your
initial question) that you do *not* have direct access to the mail
backend, I think your best solution would be to resend the emails via
SMTP to your mail server where they would be delivered as if they had
been sent there initially.
This can definitely be done via smtplib in Python by opening the mbox
file and iterating over the messages, but you may want to look at the
fetchmail utility and see if that has the capabilities (on your local
platform) required to access the mbox file directly. It's a mighty
capable utility and may be able to take care of this in a single shot.
Hope that helps,
e.
> TJG
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list